adding an object to a collection using a string (1 Viewer)

jonnydexter

Registered User.
Local time
Today, 14:03
Joined
Aug 31, 2012
Messages
21
HI
how can i add an object ( in this case a textbox) to a collection by using its name ?

Code:
colmycollection.add me.day1
- this adds the object day1 to the collection ok.

but i want to be able to add multiple objects using the count value of a loop

Code:
dim strcontrol as string  ' or should it be object ?
for i = 1 to 10
strcontrol = "day" & i
colmycollection.add me.strcontrol
next i
strcontrol needs to add the object so i can reference it properly.

thanks
 

boblarson

Smeghead
Local time
Today, 06:03
Joined
Jan 12, 2001
Messages
32,059
You can't add the actual collection that way. You can either add the control or you can add the name.

To add the control you should be able to use:

colmycollection.add Me.Controls(strcontrol), "GiveControlANameHereForUseWhenReferringToItLater"
 

jonnydexter

Registered User.
Local time
Today, 14:03
Joined
Aug 31, 2012
Messages
21
thanks bob
that has allowed me to add the control i needed.

how ever i didnt quite get the giving it a control name ( in this instance i dont need to reference it by name) but could you clarify for future reference. Is this like giving it a key ?

thanks

NVM - i looked it up and can see it is indeed a key.
thanks again
 
Last edited:

Users who are viewing this thread

Top Bottom