LOOPING records from to the end to the top?

LOOPING records from to the end to the top?

Postby sal21 » 13 May 2010, 10:13

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?
Post=16088
User avatar
sal21
BronzeLounger
 
Posts: 1453
Joined: 26 Apr 2010, 17:36

Re: LOOPING records from to the end to the top?

Postby HansV » 13 May 2010, 10:24

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:

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
Regards,
Hans
Post=16089
User avatar
HansV
Clever Clogs
 
Posts: 24146
Joined: 16 Jan 2010, 00:14
Location: Leiden, The Netherlands


Return to Access/SQL

Who is online

Users browsing this forum: No registered users and 1 guest

cron