• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

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

0
al4629740
Asked:
al4629740
  • 2
1 Solution
 
hpdvs2Commented:
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.
0
 
al4629740Author Commented:
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

0
 
shorvathCommented:
Do Until rec1.EOF = True
    'More code here
   rec1.MoveNext

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

Open in new window



or you could just put this outside the loop


Do Until rec1.EOF = True
    'More code here
   rec1.MoveNext
Loop

HoursServed(i) = HoursServed(i) & " Total = " & LoopTotal

Open in new window

0
 
al4629740Author Commented:
Excellent suggestion
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now