Solved

run code on the last record of a loop

Posted on 2012-12-27
4
180 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

12 Experts available now in Live!

Get 1:1 Help Now