We help IT Professionals succeed at work.

ADO question

ramy050799
ramy050799 asked
on
When i try to move to the last record in my ADO database using .MoveLast method i get the error "Rows does not support fetching backward -2147217884 (80040e24)"

however when i tried this with DAO it worked fine!!
Comment
Watch Question

Commented:
It's your cursor type.

Only Dynamic and Keyset types support moving forward and backword in a recordset

Try this:
'objMyConnection is the connection object
rstMyRst.open "select * from tblMyTable", & _ objMyConnection, adopendynamic, adlockoptimistic

rstmyRst.movenext
rstmyRst.movenext
rstMyrst.moveprevious
rstmyrst.movelast
Commented:
Oh yeah, by the way, if you are using SQL Server or Oracle, you need to do this before opening the Connection

objMyConnection.cursorlocation = aduseclient

Otherwise, the cursor type will always be forward only
BRONZE EXPERT
Top Expert 2012

Commented:
darthg8r

You are correct about the CursorType, however I beg to differ regarding the CursorLocation:  There is no need to set it to adUseClient

Check out the following code and you will see what I mean:

Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset
With rs
   .Source = "Select * from Customers"
   .ActiveConnection = "Provider=SQLOLEDB.1;User ID=acperkins;Initial Catalog=Northwind;Data Source=acperkins"
   .CursorType = adOpenDynamic
   .LockType = adLockBatchOptimistic
   .Open Options:=adCmdText
   .MoveNext
   .MovePrevious
   .MoveLast
   .MoveFirst
   .Close
End With
Set rs = Nothing

In any case I suspect that ramy is using Access.

Anthony
When i try to move to the last record in my ADO database using .MoveLast method i get the error "Rows
does not support fetching backward -2147217884 (80040e24)"

Were you already at the end of the recordset?

A 'adOpenStatic' cursortype supports a .movelast method only if you have not moved passed the last record to the recordset.EOF

Sorry, just did a test and you can movelast with an adOpenStatic cursortype
If a 'adOpenForwardOnly'(Which is the default) cursortype is set then a movelast method will fail
BRONZE EXPERT
Top Expert 2012

Commented:
Hornet241,

This is correct.  The only CursorType to NOT support the MoveLast method is adOpenForwardOnly.  This happens to be the default and is very typical to happen when first using ADO.

Anthony

Author

Commented:
Thank you very much everybody for your support anyways the first right answer was darthg8r's so i'll give him the points.

By the way i'm not using SQL or oracle, i'm using informix sitting on a unix server.

Ramy...

Explore More ContentExplore courses, solutions, and other research materials related to this topic.