Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Jun 2004
    Location
    Lambertville, New Jersey, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    addressing dynamic variable names (2002)

    I don't know if the subject line accurately describes the issue, but it's the best I could do right now. Here's the issue.
    I want to address some variable names in a loop using the increment value as part of the variable name. In other words I have the variables val1, val2, val3. I created a loop "For i = 1 to 3".
    In the first iteration of the loop, I want to set a value to val1. In the 2nd iteration , I want to set a value to val2, and so on.
    I've done this in other languages and one time I figured out how to do it in Access but I can't remember how I did it and can't seem to figure it out again.
    I'm looking to do something like this:

    For i = 1 to 3
    val & i = mm(i)
    next i
    Is there a function that will allow me to concatenate the "val" and the "i" into a variable name?

    Thanks for any help you can provide.

    Lance

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: addressing dynamic variable names (2002)

    That is not possible. You already have an array, so why don't you use that?

    Note: it *is* possible to refer to controls on a form or report like this:

    Me.Controls("Label" & i).Caption = mm(i)

    or

    Me.Controls("Text" & i) = mm(i)

  3. #3
    Star Lounger
    Join Date
    Jun 2004
    Location
    Lambertville, New Jersey, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: addressing dynamic variable names (2002)

    Thanks Hans;
    I don't have an array set up for destination variable. I used the source array "mm(i)" just for the purpose of the example.
    The actual code is a fairly complex iif statement

    There should be an easier way then setting up an array.
    Paradox (PAL) had a Execute() function that would let you contatinate variables and strings into an executable statement.

    Thanks for your help,
    Lance

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: addressing dynamic variable names (2002)

    Why don't you use an array Val(1 to 3) then?

    Access has an Eval function but it doesn't work with variables, only with built-in functions and references to controls on forms etc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •