VBA Table Record Count

G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top