Connecting Tech Pros Worldwide Help | Site Map

Count records of all linked tables in 2007 database

Newbie
 
Join Date: Jul 2009
Posts: 4
#1: Jul 30 '09
Do not understand this one:
SELECT
Table_Name = Name,
Row_Count = DCount("*",[MSysObjects].[Name])
FROM
MSysObjects
WHERE
(Left([Name],1)<>"~")
AND (Left([Name],4) <> "MSys")
AND ([Type] In (1, 4, 6))
ORDER BY
Name
My tables are: FES02AVTALL, FES02GRDALL, and each after etc.

this one works but returns the total number on rows that never stop:
SELECT
(Select Count(Process) From FES02AVTALL) As FY02AVT,
(Select Count(Process) From FES02GRDALL) As FY02GRD,
(Select Count(Process) From FES03AVTALL) As FY03AVT,
(Select Count(Process) From FES03GRDALL) As FY03GRD
From FES02AVTALL, FES02GRDALL, FES03AVTALL, FES03GRDALL;


all help is appriciated.

Sam
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,214
#2: Aug 1 '09

re: Count records of all linked tables in 2007 database


Quote:

Originally Posted by samvaldez View Post

Do not understand this one:
SELECT
Table_Name = Name,
Row_Count = DCount("*",[MSysObjects].[Name])
FROM
MSysObjects
WHERE
(Left([Name],1)<>"~")
AND (Left([Name],4) <> "MSys")
AND ([Type] In (1, 4, 6))
ORDER BY
Name
My tables are: FES02AVTALL, FES02GRDALL, and each after etc.

this one works but returns the total number on rows that never stop:
SELECT
(Select Count(Process) From FES02AVTALL) As FY02AVT,
(Select Count(Process) From FES02GRDALL) As FY02GRD,
(Select Count(Process) From FES03AVTALL) As FY03AVT,
(Select Count(Process) From FES03GRDALL) As FY03GRD
From FES02AVTALL, FES02GRDALL, FES03AVTALL, FES03GRDALL;


all help is appriciated.

Sam

Hello Sam, I wrote some very simple code for you that will list each Linked Table's Name along with the Number of Records contained within.
Expand|Select|Wrap|Line Numbers
  1. Dim tdf As DAO.TableDef
  2.  
  3. For Each tdf In CurrentDb.TableDefs
  4.   If Len(tdf.Connect) > 0 Then    'it is a Linked Table
  5.     Debug.Print tdf.Name & " has " & DCount("*", tdf.Name) & " Records!"
  6.   End If
  7. Next
Newbie
 
Join Date: Jul 2009
Posts: 4
#3: Aug 3 '09

re: Count records of all linked tables in 2007 database


Okay, created a command button reads like:
Private Sub Command72_Click()

Dim tdf As DAO.TableDef

For Each tdf In CurrentDb.TableDefs
If Len(tdf.Connect) > 0 Then 'it is a Linked Table (this is green out)
Debug.Print tdf.Name & " has " & DCount("*", tdf.Name) & " Records!"
End If
Next
End Sub

I did not recive anything, have I done something wrong?
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,214
#4: Aug 3 '09

re: Count records of all linked tables in 2007 database


Quote:

Originally Posted by samvaldez View Post

Okay, created a command button reads like:
Private Sub Command72_Click()

Dim tdf As DAO.TableDef

For Each tdf In CurrentDb.TableDefs
If Len(tdf.Connect) > 0 Then 'it is a Linked Table (this is green out)
Debug.Print tdf.Name & " has " & DCount("*", tdf.Name) & " Records!"
End If
Next
End Sub

I did not receive anything, have I done something wrong?

Quote:
I did not receive anything, have I done something wrong?
No, it simply means that you have no Linked Tables. To verify this, expand the previous code to:
Expand|Select|Wrap|Line Numbers
  1. Dim tdf As DAO.TableDef
  2.  
  3. For Each tdf In CurrentDb.TableDefs
  4.   If Len(tdf.Connect) > 0 Then    'it is a Linked Table (this is green out)
  5.     Debug.Print tdf.Name & "[Linked] has " & DCount("*", tdf.Name) & " Records!"
  6.   Else
  7.     Debug.Print tdf.Name & "[Non-Linked] has " & DCount("*", tdf.Name) & " Records!"
  8.   End If
  9. Next
P.S. - I intentionally did not filter out the System Tables to keep things simple,
Newbie
 
Join Date: Jul 2009
Posts: 4
#5: Aug 3 '09

re: Count records of all linked tables in 2007 database


I am working with 2007 Access.
the db i'm working in is the front end that users access. all tables are linked.

I'm i doing this correct with a command button?
Is their anything else I should do prior to copy and paste into the event of the button?

this is how command72 event reads:

Private Sub Command72_Click()

Dim tdf As DAO.TableDef

For Each tdf In CurrentDb.TableDefs
If Len(tdf.Connect) > 0 Then 'it is a Linked Table
Debug.Print tdf.Name & "[Linked] has " & DCount("*", tdf.Name) & " Records!"
Else
Debug.Print tdf.Name & "[Non-Linked] has " & DCount("*", tdf.Name) & " Records!"
End If
Next

End Sub
-------------------------

will the data open in a table?

Thanks
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,214
#6: Aug 3 '09

re: Count records of all linked tables in 2007 database


Quote:

Originally Posted by samvaldez View Post

I am working with 2007 Access.
the db i'm working in is the front end that users access. all tables are linked.

I'm i doing this correct with a command button?
Is their anything else I should do prior to copy and paste into the event of the button?

this is how command72 event reads:

Private Sub Command72_Click()

Dim tdf As DAO.TableDef

For Each tdf In CurrentDb.TableDefs
If Len(tdf.Connect) > 0 Then 'it is a Linked Table
Debug.Print tdf.Name & "[Linked] has " & DCount("*", tdf.Name) & " Records!"
Else
Debug.Print tdf.Name & "[Non-Linked] has " & DCount("*", tdf.Name) & " Records!"
End If
Next

End Sub
-------------------------

will the data open in a table?

Thanks

I just realized that I may have made an assumption that I should not have, and that is that you know how to access the DEBUG/Immediate Window. After executing this code, press the CTRL + G Key Combination to Open the DEBUG/Immediate Window. Another Option is to replace the Debug.Print Statement with Msgbox.
Newbie
 
Join Date: Jul 2009
Posts: 4
#7: Aug 3 '09

re: Count records of all linked tables in 2007 database


Great!
Changed to Msgbox. However, it is only returning non-linked tables.

is their also a way to have all listed in one box or querry/table?

thanks for your help.

Sam
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,214
#8: Aug 3 '09

re: Count records of all linked tables in 2007 database


Quote:

Originally Posted by samvaldez View Post

Great!
Changed to Msgbox. However, it is only returning non-linked tables.

is their also a way to have all listed in one box or querry/table?

thanks for your help.

Sam

Copy and Paste the following SQL Statement into the SQL View of the Query Design Window and everything that you request will be in the Form of a Query.
Expand|Select|Wrap|Line Numbers
  1. SELECT MSysObjects.Name,IIF([Type]=4,'Linked','Non-Linked') As Status,  
  2. DCount("*",[MSysObjects].[Name]) AS[Record Count]
  3. FROM MSysObjects
  4. WHERE (((Left([Name],1))<>"~") AND ((Left([Name],4))<>"MSys") AND 
  5. ((MSysObjects.Type) In (1,4,6)))
  6. ORDER BY MSysObjects.Name;
Sample OUTPUT for my PC:
Expand|Select|Wrap|Line Numbers
  1. Name          Status                    Record Count
  2. Bkup_Ctrl    Non-Linked                 1
  3. Categories    Non-Linked                 8
  4. Customers    Non-Linked               93
  5. dbo_authors    Linked               23
  6. dbo_titles    Linked                               18
  7. Employee_ImportErrors    Non-Linked    225
  8. Employees    Non-Linked    9
  9. Employees2    Non-Linked    1
  10. Horatio    Non-Linked    10
  11. Order Details    Non-Linked    2158
  12. Orders    Non-Linked    856
  13. Products    Non-Linked    77
  14. ServiceRec    Non-Linked    10
  15. Shippers    Non-Linked    3
  16. Suppliers    Non-Linked    29
  17. Table1    Non-Linked    6
  18. TBL_DATA    Non-Linked    4
  19. tbl_EXTRACT_070709    Non-Linked    1
  20. tblAccount    Non-Linked    9
  21. tblCrop    Non-Linked    5
  22. tblDOS    Non-Linked    4
  23. tblEMailAddress    Non-Linked    4
  24. tblEmployee    Non-Linked    225
  25. tblKeywords    Non-Linked    4
  26. tblOrders    Non-Linked    9
  27. tblPrefixes    Non-Linked    3
  28. tblReports    Non-Linked    2
  29. tblSales    Non-Linked    3
  30. tblSuffixes    Non-Linked    4
  31. tblTest    Non-Linked    6
  32. tShipDetails    Non-Linked    16
P.S. - Sorry, simply do not have the time to properly Format the results.
Reply


Similar Microsoft Access / VBA bytes