Link to home
Start Free TrialLog in
Avatar of SpaceCoastLife
SpaceCoastLife

asked on

Listing Ms-access tables and Record Count

How can I execute an Access 2002 query listing every table in the db and the record count in each table?
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

You might be able to make a  query for it, using the msysobjects table, though I never tried that. This code should work if you just want to get an idea of the result:
Public Function list_table_and_count()
   Dim tdf As DAO.TableDef
   For Each tdf In CurrentDb.TableDefs
      Debug.Print tdf.Name, DCount("*", tdf.Name)
   Next
End Function

Open in new window

Avatar of SpaceCoastLife
SpaceCoastLife

ASKER

The information is there (Debug) but How can I get it to display in a query or report?
Continuing on Anders solution
Public Function getTableCount(tableName As String) As Long
   Dim tdf As DAO.TableDef
   Dim tableCount As Long
   For Each tdf In CurrentDb.TableDefs
   If tdf.Name = tableName Then
      tableCount = DCount("*", tdf.Name)
     Exit For
   End If
   Next
getTableCount = tableCount
End Function

Open in new window

John: Where do I put this code? In a form? Where are the results shown?
You put in a module and you call it anywhere as (e.g. QUery
myTable: getTableCount("MyTableName")

Open in new window

Sorry for being so dense but I'm not getting it. I have your code in a module exactly as it was written and in a form as:

Call getTableCount("MyTableName"). I also tried "tempClient" instead of "MyTableName" but in either case nothing happens.

I tried it the code section of a query but that's not going to work either
just replace the "MyTableName" with the name of one of your tables.
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, guys.