DAO\ADO RecordCount

cable

Access For My Sins
Local time
Today, 20:36
Joined
Mar 11, 2002
Messages
226
In DAO I use:
Code:
rs.movelast:rs.movefirst
icount=rs.recordcount
Do I need the movelast/first when I do it with a dynamic rs in ADO?

Oh and how will it respond when the rs is empty, or when invalid? is it 0 in both cases or -1? don't suppose it matters, i can check for <1.
 
If memory serves, you don't need the movelast/movefirst in ADO. However, the default recordset type is open forward only / read only so the recordcount is always -1. You'll need to open a different type of recordset to get an accurate recordcount (like adOpenStatic).
 
so opening it dynamic, wont give a proper recordcount?

its a pain, as this is should be a simple test...but unfortunatly a sql server down the line is screwed so I can't just run the code:(
 
If you just want to see if there are any records in the recordset, you're better off testing to see if you're at the boundaries of the recordset using:
Code:
If rst.BOF and rst.EOF Then
    'There are no records
End If
Depending on the recordset type you open, getting a proper recordcount requires populating the entire recordset (like using MoveLast).

If you need an actual count, use something other than the default adOpenForwardOnly type like adOpenDynamic, adOpenKeyset, or adOpenStatic.
 

Users who are viewing this thread

Back
Top Bottom