Solved

run code on the last record of a loop

Posted on 2012-12-27
4
181 Views
Last Modified: 2012-12-28
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
Comment
Question by:al4629740
  • 2
4 Comments
 
LVL 8

Expert Comment

by:hpdvs2
ID: 38724812
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
 

Author Comment

by:al4629740
ID: 38725293
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
 
LVL 9

Accepted Solution

by:
shorvath earned 500 total points
ID: 38725397
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
 

Author Closing Comment

by:al4629740
ID: 38728607
Excellent suggestion
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now