Results 1 to 8 of 8
  1. #1
    MadTom's Avatar
    MadTom is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    CT and VT
    Posts
    206

    Query MSysObjects

    I have this query to list tables in my DB, I would like to add a column that shows the number of records for each table.
    I can do this for one table, but not with MSysObjects.


    Thanks!

    Code:
    SELECT MSysObjects.nameFROM MSysObjects
    WHERE MSysObjects.type In (1,)
       and MSysObjects.name not like '~*'      
       and MSysObjects.name  like 'tblPartsB*'
    ORDER BY MSysObjects.name;

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    stay out of the MSysObjects.
    Theres nothin you need there.

    Code:
    dim db as database
    dim tdf as tabledeff
    
    
    Set db = CurrentDb
    For Each tdf In db.TableDefs
       If InStr(tdf.name, "MsSys") = 0 and left(tdf.name,1) <> "~" then
           debug.print  tdf.name, dcount("*", tdf.name)
       endif
    Next
    MsgBox "Done"
    
    
    Set tdf = Nothing
    Set db = Nothing

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  4. #4
    MadTom's Avatar
    MadTom is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    CT and VT
    Posts
    206
    I can't get your code to work the way I needed, I had to change "dim tdf as tabledeff" , runs but doesn't show count.
    I know you don't like
    MSysObjects, but I got my query to work the way I needed it.
    This query I'm using in a combo box, Table Name and RecCount.
    Thanks,

    My Query
    Code:
    SELECT MSysObjects.Name, DCount("*","[" & [Name] & "]") AS RecCountFROM MSysObjects
    WHERE (((MSysObjects.Name) Not Like '~*' And (MSysObjects.Name) Not Like "TMPCLP" And (MSysObjects.Name) Like 'tblPartsB*') AND ((MSysObjects.type) In (1)))
    ORDER BY MSysObjects.Name;


  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,409
    You’ll need a function to return the recordcount From tabledefs. Perhaps something like

    function rcount(tname as string) as long
    rcount=tabledefs(tname).recordcount
    end function

    Free typed so may be errors

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,973
    I disagree and don't have any problems with querying MSysObjects.
    It is read only and you cannot do any harm by querying it.
    As far as I am concerned, querying MSysObjects is a very useful tool in any serious developer's toolkit

    However I would modify the query to get all local non-system tables:

    Code:
    SELECT MSysObjects.Name, DCount("*","[" & [Name] & "]") AS RecCount
    FROM MSysObjects
    WHERE (((MSysObjects.type)=1) AND ((MSysObjects.Flags)=0))
    ORDER BY MSysObjects.Name;
    You can reinstate the filter for tables starting tblPartsB* if you wish.

    Code:
    SELECT MSysObjects.Name, DCount("*","[" & [Name] & "]") AS RecCount
    FROM MSysObjects
    WHERE (((MSysObjects.Name) Like "tblPartsB*") AND ((MSysObjects.type)=1) AND ((MSysObjects.Flags)=0))
    ORDER BY MSysObjects.Name;
    Last edited by isladogs; 12-21-2020 at 05:43 PM.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    MadTom's Avatar
    MadTom is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    CT and VT
    Posts
    206
    Thanks Collin, Had a bit of setup for my combo box, but that does the trick.
    Mad-Tom
    Code:
    SELECT [QueryPartsTables].[name], [QueryPartsTables].[RecCount] FROM QueryPartsTables;

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 07-12-2018, 11:14 PM
  2. Replies: 4
    Last Post: 05-05-2018, 09:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums