VBA Table Record Count

D

David Widener

Is there an easy way to count the records in a table without opening the
table and counting each record some sort of a listfile function the gives you
a count ???, any help would be appreciated.
 
L

Lynn Trapp

Create a saved query that pulls all the records from your table and then
call the following function.

Public Function GetRecordCount()
Dim rst As DAO.Recordset
Dim lngCount As Long

Set rst = CurrentDb.OpenRecordset("YourQuery")

With rst
.MoveFirst
.MoveLast
lngCount = .RecordCount
End With

Debug.Print "Number of Records = " & lngCount

End Function
 
A

Andi Mayer

Is there an easy way to count the records in a table without opening the
table and counting each record some sort of a listfile function the gives you
a count ???, any help would be appreciated.

currentdb.TableDefs("myTablename").RecordCount
 
R

Rick Brandt

Andi said:
currentdb.TableDefs("myTablename").RecordCount

The above only works against a local Jet table. A linked table of any kind
will just return -1.
 
Top