Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count All Records in Every MS Access Table 1

Status
Not open for further replies.

eerich

IS-IT--Management
Nov 2, 2003
124
US
Hi Everyone,

I'm hoping someone can help me with a query design to count all records (rows) within each table of an Access database. For example, I have about 20 tables and I would like to list the table name (MSysObjects.Name)and the total count of records within each table (count(*) as TtlRecs). My code I attempted was:

Code:
SELECT MSysObjects.Name, count(*) as TtlRecs
FROM MSysObjects
WHERE (((MSysObjects.[Type])=1)
GROUP BY Name
ORDER BY 1;

The results produce each table name but the count is just showing 1. I'd appreciate any help on adjusting the query to count the actual records within each table.
 
You do this with some code from faq701-4233. Add the Concatenate function to a blank module and then modify your query to:

SQL:
SELECT MSysObjects.Name, Concatenate("SELECT COUNT(*) FROM [" & [Name] & "]") AS RecCount
FROM MSysObjects
WHERE MSysObjects.Type=1 AND [Name] Not like "Msys*"
ORDER BY 1;

Duane
Hook'D on Access
MS Access MVP
 
Duane - Thanks.

It is close to working but not sure why I receive an error stating:
"Runtime Error 3078; Microsoft Access database engine cannot find the input table or query "
Make sure it exists and that it is spelled correctly."

Once I click the END button it shows the tables and record counts. Any idea how to fix the error? I have no understanding of the module code, just SQL.

 
One more thing to add - the error line item in the module is line 53:
Set rs = db.OpenRecordset(pstrSQL)
 
Why the Concatenate function ?
SQL:
SELECT [Name], DCount("*","[" & [Name] & "]") AS RecCount
FROM MSysObjects
WHERE Type=1 AND [Name] Not Like "Msys*"
ORDER BY 1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV and Duane,

That worked perfectly!

Many thanks!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top