• Loop – Loopy (2000)

    Author
    Topic
    #414485

    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 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!

    Viewing 3 reply threads
    Author
    Replies
    • #921428

      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.

    • #921429

      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.

      • #921749

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

      • #921750

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

    • #921426

      At the end of the outer loop, don’t you have ?

    • #921427

      At the end of the outer loop, don’t you have ?

    Viewing 3 reply threads
    Reply To: Loop – Loopy (2000)

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

    Your information: