Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO recordset returned

Status
Not open for further replies.

Beesknees

Programmer
Feb 27, 2001
95
0
0
GB
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?
 
Hi Mark,

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.

Hope this helps

Marty
 
Hi markbeeson and martyl,

An even better way, is to use:-

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)

Regards CodeFish
 
You have to do what CodeFish say!

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.

Always check bouth BOF and EOF properties!

Tibi
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top