tags:

views:

127

answers:

2

Hi !

I made a user interface in VBA with many textbox. I read an excel sheet and I put all the value of this one in all the textbox of my user inteface. So the user can modify the values and then save it in the excel sheet.

Because we can't name the textbox like array (textBox(1), textbox(2)....) this is hard to fill the textbox by using a loop function.

I tried to use tag or tabindex property but I don't find the good way to proceed .... Is someone know an easy way to solve this !!!

Thanks

A: 

Iterate the form's control collection.

An example, say your user form is called myForm, then

myForm.Controls(i)

gets you a handle for any control in myForm. Now you can use control properties to identify which one you're looking at (label, textbox, button, etc). I'd suggest you use a Tag such as, hmmmm.... "TEXTBOX", to ease the process of id.

if myForm.Controls(i).Tag="TEXTBOX" then 'it's my textbox ! hurraay!!!
jpinto3912
Thanks, I use myForm.Controls(i).Text and this is working well. Thanks for the hint !!!
Word of caution, VB resolves objects properties at runtime, and Text is a property name that does not exist, e.g., for labels (and other controls)... So, you'll have to check your err.number after a On Error GoTo Next, or avoid it completely by checking properties that exist for all controls (tag, name, etc).Glad I could help.
jpinto3912
A: 

Yes you can.

Name your textboxes Textbox1, Textbox2 etc, then access them with

Form.Controls("Textbox" & ID)
GSerg