I think....
When i loop in recorset with rs.eof the code read from the top to the end of list, or not?
If yes, how to loop in recordset from the end to the top of list, is this possible?
LOOPING records from to the end to the top?
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: LOOPING records from to the end to the top?
To loop backwards, you need to open a recordset with the adOpenKeyset option; by default, a recordset will be opened with adOpenForwardOnly.
Here is some sample code, using a connection cnn and a recordset rst:
Here is some sample code, using a connection cnn and a recordset rst:
Code: Select all
' Open recordset (I assume the connection has already been opened)
rst.Open "MyTable", cnn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
' Go to the last record in the recordset
rst.MoveLast
' Loop until you're at the beginning
Do While Not rst.BOF
' Your code here
...
' Go to the previous record
rst.MovePrevious
Loop
' Close the recordset
rst.Close
Set rst = Nothing
Best wishes,
Hans
Hans