P
Phantom
Hi ~
I've been going through the archives and I can't seem to find a
solution for my problem. I have created a form ("UserForm1") that
consists of 16 text boxes, 7 labels, and 4 check boxes. I've created a
process that will populate the 16 text boxes, but I have to
individually call out each of the 16 text boxes to populate data. ex.
UserForm1.txtTextBox1.Value = "blah" and so on. Is there an easier way
to do it? I only want to search for the text boxes and then populate
them w/ my data. I'm trying to make my code as generic as possible and
I'm not sure how to accomplish that. I'm a newbie at VBA so it's
taking a while to get a handle on it. So, here are my questions:
1. Is it possible to loop through each of the text boxes and populate
them with data? For example, "For Each <TextBox> in
UserForm1.Controls....."
2. Also, is there a way to pass an array pointing to a particular text
box? Or, instead of typing the exact reference of the txtTextBox, can
I pass the reference as a paramater? For example, I would like to have
the value of "blah5" in UserForm1.txtTextBox5.Value.
This is what I have so far....
Example:
Dim myTextBox as TextBox
Dim myFormCtrl as Control
For each myFormCtrl in UserForm1.Controls
If TypeName(myFormCtrl) = "TextBox" Then
<What do I do here?>
End If
Next
I hope that I've explained the problem for you. Any help that you
could provide would be very much appreciated.
I've been going through the archives and I can't seem to find a
solution for my problem. I have created a form ("UserForm1") that
consists of 16 text boxes, 7 labels, and 4 check boxes. I've created a
process that will populate the 16 text boxes, but I have to
individually call out each of the 16 text boxes to populate data. ex.
UserForm1.txtTextBox1.Value = "blah" and so on. Is there an easier way
to do it? I only want to search for the text boxes and then populate
them w/ my data. I'm trying to make my code as generic as possible and
I'm not sure how to accomplish that. I'm a newbie at VBA so it's
taking a while to get a handle on it. So, here are my questions:
1. Is it possible to loop through each of the text boxes and populate
them with data? For example, "For Each <TextBox> in
UserForm1.Controls....."
2. Also, is there a way to pass an array pointing to a particular text
box? Or, instead of typing the exact reference of the txtTextBox, can
I pass the reference as a paramater? For example, I would like to have
the value of "blah5" in UserForm1.txtTextBox5.Value.
This is what I have so far....
Example:
Dim myTextBox as TextBox
Dim myFormCtrl as Control
For each myFormCtrl in UserForm1.Controls
If TypeName(myFormCtrl) = "TextBox" Then
<What do I do here?>
End If
Next
I hope that I've explained the problem for you. Any help that you
could provide would be very much appreciated.