Renaming controls en-mass

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."
 
J

John Spencer (MVP)

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
 

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

Similar Threads

Thought you should see this 1
Hiding an empty value 4
Show gif while form is "thinking" 9
Leave button pushed in 2
Weird message 5
Hding menu bar 2
Set value in non-displayed fields 2
Problems with OrderBy 3

Top