Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a string to reference an object on a form

Status
Not open for further replies.

mdav2

Programmer
Aug 22, 2000
363
GB
I have a few objects on a form that all have the same name apart from a number on the end. Textbox1, Textbox2,.. etc.

I need to be able to use a string value to substitute the object name 'textbox1'.

I can build the string name easily but then replacing it in a refenece (eg form1.textbox1) is the bit that I am stuck on.

Anyone have any idea how I would do this
 
How about:

Dim c As Control

For Each c In Me.Controls

If c.ControlType = acTextBox Then
MsgBox c.NAME
End If

Next c Hope this is ok. If not, just let me know.

Nick (Everton Rool OK!)
 
Thanks for the quick responses pezamsytik and nickjar2.

Using the controls collection was the only way I could think of getting around the problem too. The extra coding for such few objects isn't really worth it so I'll just repeat the same code 'x' times.

I still can't believe there is no string substitution but Word VBA is very limited.

I am not sure that Everton Rule though.
 
LOL!

I am an avid Everton fan!!! Hope this is ok. If not, just let me know.

Nick (Everton Rool OK!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top