dynamic named text boxes

A

Andy G

I want to loop through a set of text boxes three at a time (5 rows of 3).
I'm getting object required error on the lines that are like fa1.Name =
"txt" & CStr(box1).

Text box names:
1st run - txt11, txt12, txt13
2nd run - txt21, txt22, txt23
3rd run - txt31, txt32, txt33
4th run- txt41, txt42, txt43
5th run - txt51, txt52, txt53

Any suggestions?

box1 = 1
box2 = 2
box3 = 3

Do Until cnt = 5
Dim fa1, fa2, fa3 As TextBox
Dim cnt, box1, box2, box3 As Integer

box1 = box1 + 10
box2 = box2 + 10
box3 = box3 + 10

fa1.Name = "txt" & CStr(box1)
fa2.Name = "txt" & CStr(box2)
fa3.Name = "txt" & CStr(box3)

'I do stuff here refering to the dynamic names text boxes

cnt = cnt + 1
Loop
 
G

Guest

Andy,

I'm afraid I can't help with the object error, but since you're
redimensioning box1, box2, and box3 within the loop, they will always have
the values 11, 12, and 13.

Sprinks
 
A

Andy G

For everyone, this is how you do what I was originally asking...a little
patience always helps. A little info before you look at the code, I have 15
text boxes aranged in a 3x5 grid. The first three are named txt11, txt12,
txt13; the next line is txt21, txt22, txt23; and so on. That's why the Step
by 10 ending at 51.

Dim fa1 As TextBox
Dim fa2 As TextBox
Dim fa3 As TextBox
Dim i As Integer

'Loop through all 5 rows of fund account search boxes
For i = 11 To 51 Step 10

'Set the first line of fund acct search text box names
Set fa1 = Me("txt" & i)
Set fa2 = Me("txt" & i + 1)
Set fa3 = Me("txt" & i + 2)

Next

You can now reference fa1 and get all the properties of a text box. Same
syntax for list boxes, combo's, ect...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top