Do While until the penult record! How can I do this?

mfaqueiroz

Registered User.
Local time
Today, 07:01
Joined
Sep 30, 2015
Messages
125
Hei, everyone :)
I'm doing a do while cycle and I want that it finish at the last bue one record, do you have idea how I can do this?

The idea is represent in the following code, but off course ins't working in this way

Do While rs.EOF-1
||||
||||
Loop


grateful for your help!
 
This is an unusual requirement. How do you know what the last record will be? More typically you would modify what you do in a loop based on data in the record, not in its position.
 
Maybe something like this?

Code:
Dim i as Long
'set the record count
If Not rs.EOF And Not rs.BOF then
    rs.MoveLast
    rs.MoveFirst
Else
    Exit Sub  'No records
End If
For i = 1 to rs.RecordCount - 1
   'whatever
    rs.MoveNext
Next i
 
Use a query.

First:
The ultimate record will be
Select Top 1 XXX from YourTable
where mmmmm
orDER by LLLLLL

and
Second
the penultimate (the second highest/latest) record will be the top1 not in the first query.

Select top 1 XXX from yourTable
where xxx Not IN
(Select Top 1 XXX from YourTable
where mmmmm
ORDER by LLLLLL)
 
penultimate (the second highest/latest) record will be the top1 not in the first query.

Doesn't penultimate mean second to last? I was under the impression he wanted everything except the last record.
 
sneuberg,

You're probably correct. The OP should use a query to order the recordset.
As you mentioned, he could then do a Movelast; recordcount, then set up a process loop
to go 1 to recordcount-1.

However, it isn't really clear what the OP is trying to accomplish, and, as Markk said, It is an unusual request. I think we should have the OP restate his objectives in plain English, and then provide some options.
 
Thank you for all the tips! :) I did in this way and worked
Do While rs.EOF
If rs.EOF then
else
my code
end if
loop

So, where is achieved the last record vba don't read him, in this way the last record processed by my code is the penultimate one. :)
 
Thank you for all the tips! :) I did in this way and worked
Do While rs.EOF
If rs.EOF then
else
my code
end if
loop

So, where is achieved the last record vba don't read him, in this way the last record processed by my code is the penultimate one. :)

I just do not see how this code can do what you want?
 

Users who are viewing this thread

Back
Top Bottom