Renaming controls en-mass

  • Thread starter Thread starter Jonathan Blitz
  • Start date Start date
J

Jonathan Blitz

I have a form with over 50 controls where I need to change the names of all
the controls (according to a rule). Is there any way I can do this from code
or do I have to do this one by one by hand?

--
Jonathan Blitz
AnyKey Limited
Israel

"When things seem bad
Don't worry and shout
Just count up the times
Things have worked themselves out."
 
It kind of depends on the rule.

You can write code to step through all the controls and set the name property of
the controls. In module, the code might look something like the UNTESTED code
that follows. This simply adds a one up number to the end of the control name.

Public Sub sRenameAllControls (frmAny as Form)

Dim cntlAny as Control
Dim intAddOne as integer


For Each cntlAny In frmAny.Controls
intAddOne = intAddOne + 1
cntlAny.Name = ctnlAny.Name & IntAddOne
Next cntlAny

End Sub

You could call it from the immediate window, if the form was open in design view.

sRenameAllControls Forms!SomeFormName
 
Back
Top