Is there an easy way to tell if records have been returned for a recordset. if the recordcount is -1 it seems like that could mean it but depends on the provider. any advice?
The easiest way I know of is to check the .EOF(End of File) property of the recordset object.
For example:
Dim RSTest as ADODB.Recordset
Set RSTest = New ADODB.Recordset
RSTest.Open "SELECT * FROM Table", MyConnection
If Not RSTest.EOF Then
'Process the recordset
Else
'There were no records in the recordset
End If
I seem to recall that you can use the recordcount property but you have to move to the end of the recordset first. But this may be provider specific also. At any rate I pretty standardly use the "Not RS.EOF" method and have never had any problems.
If Not (RSTest.EOF and RSTest.BOF) Then
'Process the recordset
Else
'There were no records in the recordset
End If
If you open a Recordset object containing no records, the BOF and EOF properties are both set to True. (the value of the Recordset object's RecordCount property setting depends on the cursor type)
If You open a recordset based on a query what SUM some records and if You check the EOF that will return False because the query will return a record with NULL value.
markbeeson,
RECORDCOUNT property of ADO should return the total number of records returned, provided your have chosen KEYSET or STATIC type cursor. Somewhere I had read that, in certain circumstances your cursor-type selection may be ignored and substituted by a different cursor-type.
If you are using FORWARD ONLY cursor, your "myADORecordset.RECORDCOUNT," may result in -1.
CodeFish's listing is what I use to test if there is any record in the recordset.
-fred
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.