First of all, are you using ADO or DAO?
From your other post it appears that you are using DAO.
The replies you have here are only valid for ADO. If you are using DAO in order to get an accurate record count you first need to move to the end of the recordset then call the Recordcount() method.
I would suggest testing for records first otherwise you will raise an error if there are no records.
Dim lCount As Long
If rs.BOF = True and rs.EOF = True Then
' You no there are no records
' You can return zero
lCount = 0
Else
' Move to the last record
rs.MoveLast
' I prefer to move back to the first
rs.MoveFirst
' Now call the recordcount
lCount = rs.Recordcount
End If
You can read the help files to learn more about the recordset objects methods and properties and how to use them.
Larry Asher
|