Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Jan 2002
    Location
    Washington State
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Containers (A2K)

    Hi all!

    In a list box I need to display a list of tables located in a different Access database. I about have it. The following code lists all the tables, but it also lists queries and the hidden system tables. How do I hide the queries and the hidden system tables? Thanks!

    Set db = DBEngine.Workspaces(0).OpenDatabase(strFileName)
    Set ctr = db.Containers("tables")

    For intLoop = 0 To ctr.Documents.Count - 1
    strDocs = strDocs & ctr.Documents(intLoop).Name & ";"
    Next intLoop

    'Trim the trailing semicolon
    If Len(strDocs) <> 0 Then
    strDocs = Left(strDocs, Len(strDocs) - 1)
    End If 'Len(strDocs) <> 0

    Me!lboTables.RowSource = strDocs

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Containers (A2K)

    The 'Tables' container contains all stored tables and queries, so it may not be the ideal instrument to return only tables. You could use the TableDefs collection instead:
    <code>
    Dim db As DAO.Database
    Dim tdf As DAO.TableDef
    Dim strDocs As String

    Set db = DBEngine.Workspaces(0).OpenDatabase(strFileName)
    For Each tdf In db.TableDefs
    ' Exclude system tables
    If Not Left(tdf.Name, 4) = "MSys" Then
    strDocs = strDocs & tdf.Name & ";"
    End If
    Next tdf
    ...
    </code>
    See the thread starting at <post:=301,765>post 301,765</post:> for yet another method.

  3. #3
    Star Lounger
    Join Date
    Jan 2002
    Location
    Washington State
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Containers (A2K)

    Perfect!

    Thanks Hans!

    Do you happen to know why the "Tables" container includes queries? Why don't "Queries" have their own container?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Containers (A2K)

    Tables and select queries to a large extent play the same role in a database: they can be used as record source for a form or report, and as the row source of a list box or combo box.
    In VBA code, you can open a recordset on a table or select query, etc.
    This is also the reason why you can't give a query the same name as a table.

  5. #5
    Star Lounger
    Join Date
    Jan 2002
    Location
    Washington State
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Containers (A2K)

    Good to know. Thanks again! Have a good night, Hans!

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Containers (A2K)

    You're welcome. Have a pleasant evening!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •