Hi all,
not sure if the code below works or not so can someone test it for me.
I can get it to run, I input the form name and it says conversion complete, but when I check the form in design mode the name and control are still the same with no prefix
I made a macro for this to run.......
runcode function name fConvertControlNames()
what am I doing wrong? :banghead: I could of added the prefix myself in the time I've wasted with this
I got the code from here http://www.utteraccess.com/wiki/index.php/Naming_Conventions
thanks
peter
not sure if the code below works or not so can someone test it for me.
I can get it to run, I input the form name and it says conversion complete, but when I check the form in design mode the name and control are still the same with no prefix
I made a macro for this to run.......
runcode function name fConvertControlNames()
what am I doing wrong? :banghead: I could of added the prefix myself in the time I've wasted with this
I got the code from here http://www.utteraccess.com/wiki/index.php/Naming_Conventions
thanks
peter
Code:
'==============================================================================
' NAME: fConvertControlNames
' DESC: Converts the prefix on Controls for a new form
' RETURNS: Boolean: False if function failed
' ARGS: Optional strFormName: Name of the form to perform the operation on
' If ommited you will be prompted for the form name
' Optional bNotifyCompletion: notify when completed
'
'==============================================================================
'ErrStrV3.01
Public Function fConvertControlNames( _
Optional strFormName As String = "", _
Optional bNotifyCompletion As Boolean = True _
) As Boolean
On Error GoTo Error_Proc
Dim Ret As Boolean
'=========================
Dim strFieldPrefix As String
Dim strControlPrefix As String
Dim iLenFieldPrefix As Integer 'length of the field prefix
Dim frm As Form
Dim ctl As Control
Dim bFlag As Boolean 'loop flag
Dim i As Integer 'loop counter & msgbox return
'=========================
'change these to match your convetions
strFieldPrefix = "fld"
strControlPrefix = "ctl"
'init field prefix length
iLenFieldPrefix = Len(strFieldPrefix)
'check for a provided formname, prompt if none
If Len(strFormName) = 0 Then
strFormName = InputBox("Please enter the Form Name:")
End If
'make sure they entered something
If Len(strFormName) = 0 Then
MsgBox "No Form Name supplied, the function will exit"
GoTo Exit_Proc
End If
'make sure the form exists
bFlag = False
For i = 0 To CurrentProject.AllForms.Count - 1
If CurrentProject.AllForms(i).name = strFormName Then bFlag = True
Next
If Not bFlag Then
MsgBox "The Form Name you entered (" & strFormName & _
") does not exist!", vbCritical
GoTo Exit_Proc
End If
'if the form is open prompt the user to close it...
For Each frm In Forms
If frm.name = strFormName Then
i = MsgBox("The form " & strFormName & " is open and will need " & _
"to close to perform the operation. Would you like " & _
"to close the form and continue? Changes will be " & _
"saved...", vbYesNo, "Close Form?")
If i = vbYes Then
DoCmd.Close acForm, strFormName, acSaveYes
Else
MsgBox "Function Cancelled, no changes made"
GoTo Exit_Proc
End If
End If
Next frm
Set frm = Nothing
'now that we know the form exists and is not in use, we'll do
'what we came to do...
'open form in hidden design view
DoCmd.OpenForm strFormName, acDesign, , , , acHidden
'loop the controls, checking for the field prefix and converting when found
For Each ctl In Forms(strFormName)
If Left(ctl.name, iLenFieldPrefix) = strFieldPrefix Then
ctl.name = Replace(ctl.name, strFieldPrefix, strControlPrefix, 1, 1)
End If
Next ctl
'save and close the form
DoCmd.Close acForm, strFormName, acSaveYes
'notify if required
If bNotifyCompletion Then
MsgBox "Conversion complete"
End If
Ret = True
'=========================
Exit_Proc:
Set frm = Nothing
Set ctl = Nothing
fConvertControlNames = Ret
Exit Function
Error_Proc:
Ret = False
Select Case Err.Number
Case Else
MsgBox "Error: " & Trim(Str(Err.Number)) & vbCrLf & _
"Desc: " & Err.Description & vbCrLf & vbCrLf & _
"Module: zDEVmodTools, Procedure: fConvertControlNames" _
, vbCritical, "Error!"
End Select
Resume Exit_Proc
Resume
End Function