By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,479 Members | 2,239 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,479 IT Pros & Developers. It's quick & easy.

How to refer to a form control programmatically

P: n/a
If I have several text boxes on a form, ie. txtBox1, txtBox2, txtBox3,
etc., how can I refer to each in a loop. I want to do something
similar to this:

Dim i as Integer

for i = 0 to 2
(txtBox & cstr(i)) = something
next

The above does not work. Can I accomplish this via other means?
Thanks.

May 14 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 14 May 2006 15:27:48 -0700, Vincent wrote:
If I have several text boxes on a form, ie. txtBox1, txtBox2, txtBox3,
etc., how can I refer to each in a loop. I want to do something
similar to this:

Dim i as Integer

for i = 0 to 2
(txtBox & cstr(i)) = something
next

The above does not work. Can I accomplish this via other means?
Thanks.


For i = 0 to 2
Me("txtBox" & i) = Something
Next i
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
May 14 '06 #2

P: n/a
Vincent wrote:
If I have several text boxes on a form, ie. txtBox1, txtBox2, txtBox3,
etc., how can I refer to each in a loop. I want to do something
similar to this:

Dim i as Integer

for i = 0 to 2
(txtBox & cstr(i)) = something
next

The above does not work. Can I accomplish this via other means?
Thanks.


Dim i as Integer

for i = 0 to 2
Me.Controls(txtBox & cstr(i)) = something
next

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
May 14 '06 #3

P: n/a
Rick Brandt wrote:
Vincent wrote:
If I have several text boxes on a form, ie. txtBox1, txtBox2,
txtBox3, etc., how can I refer to each in a loop. I want to do
something similar to this:

Dim i as Integer

for i = 0 to 2
(txtBox & cstr(i)) = something
next

The above does not work. Can I accomplish this via other means?
Thanks.


Dim i as Integer

for i = 0 to 2
Me.Controls(txtBox & cstr(i)) = something
next


As Fred's post indicates the txtBox above needs to be quoted.

for i = 0 to 2
Me.Controls("txtBox" & cstr(i)) = something
next
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


May 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.