Results 1 to 8 of 8
  1. #1
    Star Lounger
    Join Date
    Feb 2001
    Location
    South Carolina, USA
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    For next loop (Access 97/sr2)

    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

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: For next loop (Access 97/sr2)

    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:<pre>For X = 1 to 2
    Me("Total0" & X).Value = rst![IM772]
    Me("Rtotal0" & X).Value = rst![RI121]
    Next 'X</pre>

    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: <A target="_blank" HREF=http://www.microsoft.com/officedev/articles/movs101.htm>http://www.microsoft.com/officedev/articles/movs101.htm</A>)

    HTH <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: For next loop (Access 97/sr2)

    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).
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: For next loop (Access 97/sr2)

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

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: For next loop (Access 97/sr2)

    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.
    Charlotte

  6. #6
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: For next loop (Access 97/sr2)

    Charlotte and Mark:

    Whoops! <img src=/S/bingo.gif border=0 alt=bingo width=15 height=22>
    Where's that "Open Mouth, Insert Foot" smiley when you need it??? (Drk, are ya listening?) <img src=/S/grovel.gif border=0 alt=grovel width=31 height=23>

    I believe I misquoted the source, but I do remember reading that somewhere. I'll double check my references next time. <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

  7. #7
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: For next loop (Access 97/sr2)

    Ah HA! <img src=/S/lightbulb.gif border=0 alt=lightbulb width=15 height=15> It wasn't Ken Getz. It was our very own Rory in this <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Cat=&Board=acc&Number=8816&page=&v iew=&sb=&o=&vc=1#Post8816>post</A>.

    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. <img src=/S/doze.gif border=0 alt=doze width=15 height=15>

  8. #8
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: For next loop (Access 97/sr2)

    Mark,
    I appreciate the compliment in getting the two of us mixed up! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    I guess now I'll have to try and remember where I read it.....
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

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