populating textboxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a procedure in place to populate Unbounded text boxes on a form
The boxes are in a martix, simulating rackings
As I want to keep the coding simple, i would like to use for next loops to
populate first the horizontal axis, than the verical axis

my problem is how can i refer to the actual text box
The text boxes are numbers from text1 to text.....
how to assign a value using for example a me.text??? statement
how to automate the me.text??? part

Thank you
 
Marcel,

One easy trick is to use a naming convention for the text boxes like
textXY, X being the "row" number and "Y" being the "column" number; so,
assuming you have 5 rows with 3 text boxes each, your nested loop would
look something like:

For i = 1 to 5
For j = 1 to 3
Me.Controls("text" & i & j) = SomeExpression
Next
Next

HTH,
Nikos
 
There are three ways to refer to the textbox.

1) Me.txtMyTextbox
2) Me.Controls("txtMyTextbox")
3) Me.Controls(1)

Number 1 is the most familiar, number 3 would require knowing the index
number of the control, number 2 will allow what you're wanting. With number
2 you can concatenate a name value or you can use a variable that contains
the name.

Example:
For i = 1 To 10
Me.Controls("txtMyTextbox" & i) = i
Next

or

For i = 1 To 10
strTextboxName = "txtMyTextbox" & i
Me.Controls(strTextboxName) = i
Next
 
Back
Top