Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Royal Oak, Michigan, USA
    Posts
    255
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Loop - Loopy (2000)

    I haven't had much practice with Loop statements and have exhausted my resources. I have a form that runs an append query beginning with record 1 and runs until record X is reached. The form is refreshed after each record is reviewed and I'm trying to use a loop function to run the iterations from record 1 until reocrd X is reached. Here is the code I'm using:

    Private Sub cmdMakeInvoices_Click()
    Do
    Do While Me.intRecordNum <= Me.intRecordMax ' Inner loop.
    DoCmd.OpenQuery "qryInvoiceLineWrite"
    Me.bolInvoiced = -1
    Me.Requery
    If Me.intRecordNum > Me.intRecordMax Then ' If condition is True.
    Exit Do ' Exit inner loop.
    End If
    Loop
    Loop Until Me.intRecordNum <= Me.intRecordMax
    End Sub

    intRecordNum is the current record and intRecordMax is the last record to run. The me.Requery refreshes the form as the form source only pulls one record at a time. My problem with the statement above is it doesn't stop when intRecordNum is greater than intRecordMax. I'm sure there's some silly code I omitted.
    Thanks!

  2. #2
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Loop - Loopy (2000)

    Alternatively, it looks to me like your outer loop is completely redundant with your inner loop, so you should just get rid of it.

    Same for the If test at the end of the inner loop. It doesn't look like it's doing anything that the inner loop's Do condition wouldn't accomplish without it.

    If you get rid of the outer loop and the If test and the loop never stops, that must mean the substantive code within the loop isn't increasing Me.intRecordNum with each iteration.

  3. #3
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Loop - Loopy (2000)

    At the end of the outer loop, don't you have <= where you should have >?

  4. #4
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Royal Oak, Michigan, USA
    Posts
    255
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Loop - Loopy (2000)

    Thanks a bumch. The record counter wasn't refreshing. thanks for the additional advie...it works like a charm now!

Posting Permissions

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