Solved

run code on the last record of a loop

Posted on 2012-12-27
4
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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