variable name containing a variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • reginaldmerritt
    New Member
    • Nov 2006
    • 201

    #1

    variable name containing a variable

    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?

    Code:
    private sub button_click()
    dim i as integer
    dim counter as integer
    
    counter = 1
    i = 7
    
    for counter = 1 to 3
      me."bob" & i = "My Name is Bob"
      counter = counter+1
      i=i+1
    next
    
    end sub
    any suggestions welcom : )
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Try the following.
    [code=vb]
    Me.Controls("bo b" & i) = ....
    [/code]

    Comment

    • reginaldmerritt
      New Member
      • Nov 2006
      • 201

      #3
      That fabulous, easy when you know how : )
      You've proabably saved me around 2hrs work.
      Thanks for you help and your quick reply.

      Comment

      Working...