You could use a totals query and grab the count. Write a little function
and then pass the tablename and the fieldname to the function and use it to
get the recordcount for any table you want:
Function RecordsInTable(Tablename As String, Fieldname As String) As Long
Dim strSQL As String, strTableField As String
Dim rst As DAO.Recordset
strTableField = Tablename & "." & Fieldname
strSQL = "SELECT Count(" & strTableField & ") AS [Count] FROM " &
Tablename & ";"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
RecordsInTable = rst!Count
Set rst = Nothing
End Function
Here's how you call the function:
Sub test()
MsgBox "Records in table: " & RecordsInTable("Table1", "ID")
End Sub
This will work for tables with no records as well, just make sure the table
name and field name exist; you can (and should) add some error-checking.
If you use a totals query, you don't have to bother with checking for EOF
and moving to last record before you can get the record count.