• For next loop (Access 97/sr2)

    Author
    Topic
    #357673

    I have a for next statement that I want to automatically have access to move to the next text box to fill in the data. I have tried using the concatentation character but I get an error message. Any suggestions??

    For X = 1 To 2

    Me!Total&X = rst![IM772]

    Me!Rtotal&X = rst![RI121]

    Next X

    I want the text box to change to Total01 to Total02 and the same for Rtotal01 and Rtotal02. I have 30 text boxes that need to be filled in but it has to increment based on the X.

    Thanks,
    Deborah

    Viewing 0 reply threads
    Author
    Replies
    • #531844

      You’re close. I’ve struggled with the concatentation character for some time, but finally got comfortable using it – thanks to the Longe! Try this:

      For X = 1 to 2
          Me("Total0" & X).Value = rst![IM772]
          Me("Rtotal0" & X).Value = rst![RI121]
      Next 'X

      I use the .Value property for clarity, but it’s not really necessary. Also, For…Next loops will generally run faster without entering the variable after Next (courtesy of Ken Getz: http://www.microsoft.com/officedev/articles/movs101.htm)

      HTH thumbup

      • #531860

        Not to dispute anything Ken Getz said, but I don’t think there is any difference in performance in using “Next” vs “Next X”. At least my tests don’t detect any discernable difference. And “Next X” is easier to read (especially if you have nested For…Next statements).

        • #531861

          I agree about the ease of readability. I usually include the looped item as a comment: Next X.

          • #531881

            I could have sworn I’ve heard him say just the opposite in conference sessions; but regardless, I think I’ll stick with the explicit Next X and forget about any minimal performance improvement that might go with dropping it.

            • #531883

              Charlotte and Mark:

              Whoops! bingo
              Where’s that “Open Mouth, Insert Foot” smiley when you need it??? (Drk, are ya listening?) grovel

              I believe I misquoted the source, but I do remember reading that somewhere. I’ll double check my references next time. blush

            • #531884

              Ah HA! lightbulb It wasn’t Ken Getz. It was our very own Rory in this post.

              I think my mind’s database has a few corrupted records. Maybe I’ll run Compact and Repair…or maybe I’ll just try to get more sleep. doze

            • #531905

              Mark,
              I appreciate the compliment in getting the two of us mixed up! grin
              I guess now I’ll have to try and remember where I read it…..

    Viewing 0 reply threads
    Reply To: For next loop (Access 97/sr2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: