While loop?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to have it go through a series of textboxes and fill them. The
problem I'm having is that I don't know how to get it to move to the next
box. I tried:

n=1
while n < 6
Title = "Text" & n
Me!Title.SetFocus
Me!Title.Text = "blah blah blah"
n=n+1
Title = ""
wend

but it doesn't recognize that Title is the same as Text1, Text2, etc. Am I
looking at it wrong or is it impossible?
 
I'm trying to have it go through a series of textboxes and fill them. The
problem I'm having is that I don't know how to get it to move to the next
box. I tried:

n=1
while n < 6
Title = "Text" & n
Me!Title.SetFocus
Me!Title.Text = "blah blah blah"
n=n+1
Title = ""
wend

but it doesn't recognize that Title is the same as Text1, Text2, etc. Am I
looking at it wrong or is it impossible?

I'd actually use a FOR loop rather than a WHILE - a bit simpler. You can use a
different syntax to reference the control. Try

Dim n As Integer
For n = 1 to 6
Me.Controls("Text" & n) = "blah blah blah"
Next n

Note that you can simply set a control to a value: in fact the Text property
is read-only.

John W. Vinson [MVP]
 
Back
Top