View Full Version : Processing last record


Malcy
03-28-2008, 09:16 AM
I am having an issue with major processing in recordset of around 1500 records.
I start the loop with
While Not rstAprProp.EOF
and I end the loop, many lines of code later with
' Move to next record
rstAprProp.MoveNext

' Repeat the cycle
Wend
Every single record except the last one is processed with glorious accuracy but the final record is not touched. Presumably the .EOF is showing true, but I thought this happened on the first new record at the bottom of the recordset not the last record.
Can anyone set me straight please since I am feeling a ninny!
Thanks and best wishes

boblarson
03-28-2008, 09:29 AM
Try not using

While Not rstAprProp.EOF
...your code here
Wend


try using this instead:

Do Until rstAprProp.EOF
... your code here
Loop

Malcy
03-28-2008, 09:34 AM
Thanks for such a swift reply Bob
I have made change and will test - it takes a while to run through.
Just out of curiosity why use the one not the other? I presume less "thinking" needed by vba or is it just I learned an older device that has worked ok on less demanding processing?
Best wishes

boblarson
03-28-2008, 10:15 AM
check this out (yes it is for SAS but the logic is the same regardless):

http://books.google.com/books?id=7WkfycHDQX4C&pg=PA133&lpg=PA133&dq=differences+between+do+while+and+do+until&source=web&ots=YECvZvmA8I&sig=VXs5Uz9fKlPX4oOy_qUIFk8NTNQ&hl=en

Malcy
03-28-2008, 10:50 AM
Thanks for help. It still glooped at the last record so moved processing loop to
' Load the first record
' rstAprProp.MoveLast
rstAprProp.MoveFirst

' Set the counter
lngRpt = 1

' Start the looping
Do Until lngRpt = lngCount

Where lngCount is taken from a DCount of all records in recordset that need to be processed. Added a wee lngRpt = lngRpt+1 at end of the loop before the movenext
Feeling much happier now!

gemma-the-husky
03-28-2008, 04:27 PM
i think there must be something else going on

while not rs.eof
{process record}
rs.movenext
wend

will work ok

----------------
what might happen is that if you are grouping/testing whether a record is the same as the previous one, the LAST record/group ALWAYS needs processing outside the loop