mubi_masti
Registered User.
- Local time
- Today, 10:26
- Joined
- Oct 2, 2011
- Messages
- 46
Can any one help what is error in the following function to count the total number of records of a query
i always get error on line rs.close
Function TotalRecords(qryname As String) As Long
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Set dbs = CurrentDb
On Error GoTo Err_TotalRecords
Set rs = dbs.OpenRecordset(qryname)
If rs.RecordCount = 0 Then
TotalRecords = rs.RecordCount
Exit Function
Else
rs.MoveLast
TotalRecords = rs.RecordCount
End If
Err_TotalRecords:
'My code
rs.Close
Set rs = Nothing
dbs.Close
Set dbs = Nothing
End Function
i always get error on line rs.close
Function TotalRecords(qryname As String) As Long
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Set dbs = CurrentDb
On Error GoTo Err_TotalRecords
Set rs = dbs.OpenRecordset(qryname)
If rs.RecordCount = 0 Then
TotalRecords = rs.RecordCount
Exit Function
Else
rs.MoveLast
TotalRecords = rs.RecordCount
End If
Err_TotalRecords:
'My code
rs.Close
Set rs = Nothing
dbs.Close
Set dbs = Nothing
End Function