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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make many references to mane objects? 1

Status
Not open for further replies.

jakobc

Technical User
Jan 1, 2006
5
NO
I would like to make references to an unknown number (max 10) of textboxes. The name of the textboxes are "myTB1", "myTB2", "myTB3" and so on.

I know that I cold have used
**********
Dim ref1
Set ref1 = UserForm1.myTB1
Dim ref2
Set ref2 = UserForm1.myTB2
**********
... and so on...

I hva tried this:
**********
Dim i as Integer
For i=1 to 10
Dim "ref" & i
Set "ref" & i = "UserForm1.myTB" & i
Next
**********
But that didn't work.

Can anyone here help me?

By the way. I am not sure what a "Techical User" is, I didn't know the difference between the titles when I registered, so I just picked the one at the bottom hoping that it meant something like "beginner".
 
I think you should be able to do something like this:

[tt]dim lngCounter as long
for lngCounter = 1 to 10
debug.print me.controls("TB" & cstr(lngCounter)).value
next lngCounter[/tt]

Which isn't instantiating them, but allows you to refer to them dynamicly.

Roy-Vidar
 
Thank you for your reply, Roy-Vidar. But I don't understand how that was going to help me. What does this line do?:

debug.print me.controls("TB" & cstr(lngCounter)).value

I tried to set the Visible-property of TB1 to TB5 as True, but it didn't work.

Dim lngCounter As Long
For lngCounter = 1 To 10
Debug.Print Me.Controls("TB" & CStr(lngCounter)).Value
Next lngCounter
Dim i As Integer
For i = 1 To 5
("TB" & i).Visible=True
Next i
 
Something like this ?
For i = 1 To 5
Me.Controls("myTB" & i).Visible = True
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Incredible! It worked! :) Thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top