Naming controls on a form

S

SAC

I had downloaded this routine from someone's site a while back...but I can't
get it to run. I open the form in design view, open the immediate window
and
type:

NamingConventions frmMyFormName

I get "Compile Error" Type Mismatch

Do I need the whole forms!.....syntax?

Once I get this to run....is there a way to have this run on the whole forms
collection at once?

Thanks.

Public Function NamingConventions(objForm As Form) As String
'To use this function, open your form in design mode _
and call this function from the VBA immediate window, _
supplying the form name as input.

Dim c As Control
Dim strNConv As String
Dim intCount As Integer

With objForm
For Each c In objForm.Controls
Select Case c.ControlType
Case acTextBox
strNConv = "txt"
Case acComboBox
strNConv = "cbo"
Case acListBox
strNConv = "lst"
Case acCommandButton
strNConv = "cmd"
Case acImage
strNConv = "img"
Case acOptionGroup
strNConv = "opt"
Case 108
strNConv = "ole"
Case acCheckBox
strNConv = "chk"
Case acToggleButton
strNConv = "tgl"
Case 123
strNConv = "tab"
End Select

If Not c.Name Like strNConv & "*" Then
c.Name = strNConv & c.Name
intCount = intCount + 1
End If
Next
End With

NamingConventions = "Renamed " & intCount & " controls to comply with "
& _
"naming conventions."
 
P

Paul Overway

There is a free wizard available on my site (under Extras) that performs
this task.
 
P

Paul Overway

I might consider adding that ability in the future, but it probably isn;t a
good idea....too much going on at once, confuse the user, etc.

In any case, it is provided "as is".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top