VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Total Record Count In ADO Recordset

by Riaan Aspeling (14 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (39 Votes)

This simple little function just returns the total number of records in a ADO recordset.

Inputs
A ADODB.Recordset structure
Code Returns
A Long integer with the total number of records
Side Effects
I believe it's not the fastest way of retrieving the information but at least it works. I'd like it if somebody can suggest a alt. way of getting to this info.

Rate Total Record Count In ADO Recordset

'Pass this function your ADO recordset
Function GetTotalRecords(ByRef aRS As ADODB.Recordset) As Long
On Error GoTo handelgettotalrec
 Dim adoBookM As Variant 'Declare a variable to keep the current location
 adoBookM = aRS.Bookmark 'Get the current location in the recordset
 aRS.MoveLast   'Move to the last record in the recordset
 GetTotalRecords = aRS.RecordCount 'Set the count value
 aRS.Bookmark = adoBookM 'Return to the origanal record
 Exit Function
handelgettotalrec:
 GetTotalRecords = 0  'If there's any errors return 0
 Exit Function
End Function

Download this snippet    Add to My Saved Code

Total Record Count In ADO Recordset Comments

No comments have been posted about Total Record Count In ADO Recordset. Why not be the first to post a comment about Total Record Count In ADO Recordset.

Post your comment

Subject:
Message:
0/1000 characters