PDA

View Full Version : Setfocus to Textbox using a variable



Kicker
03-26-2009, 07:37 PM
I have 100 textboxes on a form in rows of 10 each. I need to use 2 for/next statements to fill the values. For example:


For n = 1 to 10
for r = 1 to 10
TextBoxVariable = "Text" & trim(str(r))
***here is where I need to assign a value to the text box
***normally I would use me.text1.value = "something"
How do I use the variable to refer to the textbox?

next i

next n


Some help would be apreciated.

hansup
03-26-2009, 10:09 PM
I have 100 textboxes on a form in rows of 10 each. I need to use 2 for/next statements to fill the values. For example:


For n = 1 to 10
for r = 1 to 10
TextBoxVariable = "Text" & trim(str(r))
***here is where I need to assign a value to the text box
***normally I would use me.text1.value = "something"
How do I use the variable to refer to the textbox?

next i

next n

Some help would be apreciated.Use the variable's value to refer to a member of the form's Controls collection.

Me.Controls(TextBoxVariable).Value = "something"

You might consider Cstr(r) instead of Trim(Str(r)).

Finally, I don't see how you cover 100 items based on the code you posted. :dunno

Good luck,
Hans