RecordCount Property

  • Thread starter Thread starter Sanjay Sangwan
  • Start date Start date
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
 
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.
 
Back
Top