-
I have ten textboxes on my form which are hidden until being populated. My question is: How do I refer to these textboxes when I'm in a loop? For example - I've tried "Text" & z - when z is set to 2 to no avail.
Old Man
[Edited by Old Man on 10-11-2000 at 05:21 PM]
-
Change the textboxes into a Control array (set the index property to something other than 0 and their names to the same thing: IE Text1 ...) After you do this, you'd refer to each one by it's name and index like an array: Text1(X) ...
-
make a control array by naming them all them same and setting the index property starting at zero
you can then refer to them as Text1(x).Visible = True
-
Or you can do it like this:
Code:
For Each MyControl In Me.Controls
If TypeOf MyControl Is TextBox Then MyControl.Visible = True
Next
-
You could also...
Code:
Dim Controlx as Control
For Each Controlx In Me.Controls
If TypeOf Controlx Is "TextBox" And Left$(Controlx.Name, 4) = "Text" Then Controlx.Visible = True
Next
WITHOUT setting a control array.
-
that might cause conflicts if there are more TextBoxes on the form with other uses. If you perfer to use Matthew Gate's solution, I suggest you consider "tagging" the objects you want to work with.
Code:
Dim ctl as Control
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
If ctl.Tag = "TAGGED" Then
'Do your code here
End if
End if
Next ctl
-
Thanks very much for your help! I got it.
Let's do lunch!!
Old Man