Hi,
I need to fill many Text Boxes as TextBox1, TextBox2 and so on ... using a FOR stattement
For i= 1 to n
("TextBox" & i).Value = "AAAAAAAAAAA"
Is it possible?
Any idea?
Thanks in advance.
Giovanni
Printable View
Hi,
I need to fill many Text Boxes as TextBox1, TextBox2 and so on ... using a FOR stattement
For i= 1 to n
("TextBox" & i).Value = "AAAAAAAAAAA"
Is it possible?
Any idea?
Thanks in advance.
Giovanni
if you use control array for your textboxes then u can do somthing like.....
For i = 0 to 5
text1(i).text = "Text"
next i
In case you don't know how to make control arrays:
-Put one control on the form and give it a name (for example txtField)
-Put another control (same type as first one) on the same form and give the same name (txtField) to it too. VB will ask you if you want to create a control array. Answer YES.
-After that all controls you name the same will be added to the array.
You will also notice that the Index property of those controls is no longer empty, it now holds the index number of a particular control in the array.
As Psycho and Baja suggested Control Array is the way to go, however the following method might also work for you: you would have to set Tag property in design for each textbox so it will function like some identifier or you can use control's name instead.
VB Code:
Private Sub Command1_Click() Dim txt As Control For Each txt In Controls If TypeOf txt Is TextBox Then Select Case UCase(txt.Tag) Case "FIRST NAME" 'do something Case "LAST NAME" 'do something End Select End If Next txt End Sub