Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Melbourne, Victoria, Australia
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    For next loop (A2003 SP-2)

    Hi,
    Instead of repeating lines of code multiple times to 'zero' out a number of controls on a form, I would like to use a loop.

    So instead of this
    Me!Pd1 = 0
    Me!Pd2 = 0
    Me!Pd3 = 0

    I would like something along the lines of this
    Dim K As Integer
    For K = 1 To 3
    Me!Pd&K = 0 (How do I get the loop using the counter to reference each one of the three, in this case, controls.
    Next K

    Thanks in advance.

    Zinger

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: For next loop (A2003 SP-2)

    Try this

    Dim strcontrolname as string
    Dim K As Integer
    For K = 1 To 3
    strcontrolname = "PD" & k
    Me(strcontrolname) = 0
    Next K
    Regards
    John



  3. #3
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: For next loop (A2003 SP-2)

    for more brevity combine the 2 commands into one as folows:

    Dim K As Integer
    For K = 1 To 3
    Me("PD" & k) = 0
    Next K

  4. #4
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Melbourne, Victoria, Australia
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: For next loop (A2003 SP-2)

    Thanks for the suggestion, I finally found the time to try it.
    It certainly makes the code far more elegant.
    Zinger

  5. #5
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Melbourne, Victoria, Australia
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: For next loop (A2003 SP-2)

    Thanks for the suggestion, I finally found the time to try it and the previous post.
    It makes the code less verbose and more elegant.
    Zinger

Posting Permissions

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