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

variable name containing a variable

reginaldmerritt
100+
P: 201
Is there a way of having a variable name containing a variable. I have some code relating to a section of fields on a form, i then have an identicle code relating to another (very simular) section of fields.

e.g.

say we had three fields named ,BOB7,BOB8,BOB9. All of which we wanted to say "My Name is Bob"
how can we do something like this?

Expand|Select|Wrap|Line Numbers
  1. private sub button_click()
  2. dim i as integer
  3. dim counter as integer
  4.  
  5. counter = 1
  6. i = 7
  7.  
  8. for counter = 1 to 3
  9.   me."bob" & i = "My Name is Bob"
  10.   counter = counter+1
  11.   i=i+1
  12. next
  13.  
  14. end sub
any suggestions welcom : )
Nov 25 '07 #1
Share this Question
Share on Google+
2 Replies


FishVal
Expert 2.5K+
P: 2,653
Try the following.
Expand|Select|Wrap|Line Numbers
  1. Me.Controls("bob" & i) = ....
  2.  
Nov 25 '07 #2

reginaldmerritt
100+
P: 201
That fabulous, easy when you know how : )
You've proabably saved me around 2hrs work.
Thanks for you help and your quick reply.
Nov 25 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.