VB icon

Total Record Count In ADO Recordset

Submitted on: 1/2/2015 5:02:00 AM
By: Riaan Aspeling  
Level: Not Given
User Rating: By 39 Users
Compatibility: VB 5.0, VB 6.0, VB Script, ASP (Active Server Pages)
Views: 1
     This simple little function just returns the total number of records in a ADO recordset.
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
' Name: Total Record Count In ADO Recordset
' Description:This simple little function just returns the total number of records in a ADO recordset.
' By: Riaan Aspeling
' Inputs:A ADODB.Recordset structure
' 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.

'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
 GetTotalRecords = 0'If there's any errors return 0
 Exit Function
End Function

Other 13 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.