Full Version: Count records in all tables.
UtterAccess Discussion Forums > Microsoft® Access > Access Tables + Relationships
mbruso
Hi,

Anyone have any code you could share or a utility I could buy, that will count all the records in each table in a database. Then write all data to a temp table.

Thanks!
Jerry Dennison
Why would you want to do this? What exactly are you trying to do?
mbruso
I am doing a detailed analysis for a client, and I need to know how many records there are in each table, so I can make intelligent recommendations.
Jerry Dennison
I suppose you could use code to iterate through the tabledef collection and get the recordcound for each item in the collection.
jinky44
Mark,

You can find an example of code that loops through the tabledef collection (excluding system tables) in the attachment found here.

(You have to cobble together some code to count/record the rows in each table and substitute it for the "none-setting code" that is in the example, though.)

And I can see why Jerry asked his question. Most clients that I've had usually want to tell ME how many rows are in their tables (several times, sometimes), not the other way around!

HTH

Jinky
Jerry Dennison
Another method you could use would be to create a simple UNION query using the following syntax:

SELECT "TableName1" AS TableName1, Count(*) AS NumRecords FROM TableName1
UNION SELECT "TableName2" AS TableName2, Count(*) AS NumRecords FROM TableName2
UNION SELECT "TableName3" AS TableName3, Count(*) AS NumRecords FROM TableName3
....;

This method would be "hardcoded" by you for each database you want to use it in.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.