Increment field name (1 Viewer)

kwennerberg

New member
Local time
Today, 14:12
Joined
Jan 11, 2011
Messages
2
In a DO Loop how does one refer to a text field that ends with a sequential number each time through the loop? How do I do the syntax for the line below which begins with "Months_String"?
For example

Dim Months_String as String
MyNbr = 64
Do Until MyNbr = 70
Months_String = Months_String & me.month64
MyNbr = MyNbr + 2
Loop
'here is issue: First time through the loop the text box referred on the form is month64, next time through the loop it is month66, month68, then month70. It could be up to 10 times through the loop. I would like to use MyNbr in the each time through the loop to alter the text box name referred to.
 

boblarson

Smeghead
Local time
Today, 12:12
Joined
Jan 12, 2001
Messages
32,059
Something like this:
Code:
Dim Months_String as String
 
MyNbr = 64
 
Do Until MyNbr = 70
 
   Me.Controls("month" & MyNbr).Value = "xxxxxxx"
   MyNbr = MyNbr + 2
Loop
 

kwennerberg

New member
Local time
Today, 14:12
Joined
Jan 11, 2011
Messages
2
:) Thanks. That did it. I will re-use this syntax for I would like to often loop through fields by number in this manner.
 

Users who are viewing this thread

Top Bottom