This example demonstrates the RecordCount property with different types of Recordsets before and after they're populated.
Sub RecordCountX()
Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
With dbsNorthwind
' Open table-type Recordset and show RecordCount
' property.
Set rstEmployees = .OpenRecordset("Employees")
Debug.Print _
"Table-type recordset from Employees table"
Debug.Print " RecordCount = " & _
rstEmployees.RecordCount
rstEmployees.Close
' Open dynaset-type Recordset and show RecordCount
' property before populating the Recordset.
Set rstEmployees = .OpenRecordset("Employees", _
dbOpenDynaset)
Debug.Print "Dynaset-type recordset " & _
"from Employees table before MoveLast"
Debug.Print " RecordCount = " & _
rstEmployees.RecordCount
' Show the RecordCount property after populating the
' Recordset.
rstEmployees.MoveLast
Debug.Print "Dynaset-type recordset " & _
"from Employees table after MoveLast"
Debug.Print " RecordCount = " & _
rstEmployees.RecordCount
rstEmployees.Close
' Open snapshot-type Recordset and show RecordCount
' property before populating the Recordset.
Set rstEmployees = .OpenRecordset("Employees", _
dbOpenSnapshot)
Debug.Print "Snapshot-type recordset " & _
"from Employees table before MoveLast"
Debug.Print " RecordCount = " & _
rstEmployees.RecordCount
' Show the RecordCount property after populating the
' Recordset.
rstEmployees.MoveLast
Debug.Print "Snapshot-type recordset " & _
"from Employees table after MoveLast"
Debug.Print " RecordCount = " & _
rstEmployees.RecordCount
rstEmployees.Close
' Open forward-only-type Recordset and show
' RecordCount property before populating the
' Recordset.
Set rstEmployees = .OpenRecordset("Employees", _
dbOpenForwardOnly)
Debug.Print "Forward-only-type recordset " & _
"from Employees table before MoveLast"
Debug.Print " RecordCount = " & _
rstEmployees.RecordCount
' Show the RecordCount property after calling the
' MoveNext method.
rstEmployees.MoveNext
Debug.Print "Forward-only-type recordset " & _
"from Employees table after MoveNext"
Debug.Print " RecordCount = " & _
rstEmployees.RecordCount
rstEmployees.Close
.Close
End With
End Sub