Article ID: 207652
Article Last Modified on 10/11/2006
Option Explicit
'===========================================================
' The following function, MyWrongRecordCount(), demonstrates
' the incorrect way to use the RecordCount property to count
' records in a dynaset.
'===========================================================
Function MyWrongRecordCount ()
Dim MyDB As DAO.Database
Dim MyRS as DAO.Recordset
Set MyDB = CurrentDB()
Set MyRS = MyDb.OpenRecordset("Customers", dbOpenDynaset)
MyWrongRecordCount = MyRS.RecordCount
MyRS.Close
End Function
'===========================================================
' The following function, MyRightRecordCount(), demonstrates
' the correct way to use the RecordCount property to count
' records in a dynaset.
'===========================================================
Function MyRightRecordCount ()
Dim MyDB As DAO.Database
Dim MyRS as DAO.Recordset
Set MyDB = CurrentDB()
Set MyRS = MyDb.OpenRecordset("Customers", dbOpenDynaset)
MyRS.MoveLast
MyRightRecordCount = MyRS.RecordCount
MyRS.Close
End Function
?MyWrongRecordCount()Note that the function returns 1.
?MyRightRecordCount()Note that the function returns the correct number of records in the Customers table.
Additional query words: record count move last
Keywords: kbdta kbofficeprog kbprb kbprogramming kbvba KB207652