Link to home
Start Free TrialLog in
Avatar of al4629740
al4629740Flag for United States of America

asked on

run code on the last record of a loop

I am trying to run the following code within a loop.  If I am on the LAST record in the loop I want the If/Then statement below to run, but its not running.  How can I make line 6 run on the very last record of the recordset in the loop?

Do Until rec1.EOF = True

 'More code here

If rec1.EOF = True Then
                    HoursServed(i) = HoursServed(i) & " Total = " & LoopTotal
End If

Loop

Open in new window

Avatar of Dan Violet Sagmiller (He/Him)
Dan Violet Sagmiller (He/Him)
Flag of United States of America image

You have a code function that moves to the next record, presumably.
such as rec1.MoveNext().  I'm presuming that you do that AFTER the rec1.eof check.  you should do that right before.
Avatar of al4629740

ASKER

This is where it happens.  Same problem

Do Until rec1.EOF = True

 'More code here

If rec1.EOF = True Then
                    HoursServed(i) = HoursServed(i) & " Total = " & LoopTotal
End If

rec1.MoveNext
Loop

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of shorvath
shorvath
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent suggestion