RecordCount Property

S

Sanjay Sangwan

Hi
I am expereincing difficulty in getting RecordCount of a
recordset generated with ADO. The code is like this

Private sub TESTONLY as integer
dim rst as new ADODB.recordset
rst.open "MYQUERY",CurrentProject.connection,
adOpenDynamic, adLockOptimistic
witt rst
.movefirst
.movelast
TestOnly =rst.Recordcount
end with
end sub


Every time the value returned is -1. I tried changing all
sorts of cursor property etc but no use. can you tell
what could be wrong. I have tested the recordset
generation which appears to be fine

Thanks in advance

Sanjay
 
V

Van T. Dinh

RecordCount of a dynamic cursor can return either -1 (your case obviously)
or the actual count depending on the datasource. I normally use static
cursor or keyset cursor which should return the actual count.

Also, with ADO Recordset, you don't need to do MoveLast / MoveFirst.

Check Access VB Help on the RecordCount Property of an ADO Recordset for
more info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top