Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use text box name field as a variable? 1

Status
Not open for further replies.

ausMuenchen

Programmer
Oct 20, 2003
6
DE
Hello,
I have a form with a large amount of text boxes, is it possible to reference these as an array , or is there an easier way to do this. I set all of the boxes to not visible when the form loads and only show them when they are filled. I am filling them in a loop with a table. I hope my explanation is ok. My first time to post here.

Thanks
 
Each textbox on your form can be referenced through the Forms Controls collection, using the name of the control as the Key into the collection.

Me.Controls(&quot;ControlName&quot;).<Property> = <Value> and you can use a variable for the ControlName.

If for example, your textboxes are Named as TextBox1, TextBox2, TextBox3, and so on, then you can do the following:

For Idx = 1 to 3
Me.Controls(&quot;TextBox&quot; & Trim(Idx)).Visible = True
Next Idx

If they are not named in any sort of &quot;loopable&quot; fashion, then you can also do the following:

Dim Idx as Integer
Dim CntrlNames(3) as String
CntrlNames(0) = &quot;FirstControl&quot;
CntrlNames(1) = &quot;SecondControl&quot;
CntrlNames(2) = &quot;txtFirstName&quot;
CntrlNames(3) = &quot;txtLastName&quot;

For Idx = 0 to 3
Me.Controls(CntrlNames(Idx)).Visible = True
Next Idx


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thank you so much, works great. I should have come here a few days ago. This will save me alot of time.

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top