Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: ActiveX Data Objects (ADO) Includes Queries and Views in the Tables Collection


View products that this article applies to.

This article was previously published under Q225895
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

↑ Back to the top


Symptoms

When you use ActiveX Data Objects (ADO) to programmatically traverse the Tables collection, you see the names of queries and views included as part of the collection.

↑ Back to the top


Resolution

Test for the type of object within the Tables collection. The table types can be:
  • ACCESS TABLE
  • SYSTEM TABLE
  • SYSTEM VIEW
  • TABLE
  • VIEW
The following ADO code will only display user created tables, or tables created if you encounter import errors:
Sub FindOnlyTables()

   Dim cat As New ADOX.Catalog
   Dim tbl As ADOX.Table

   cat.ActiveConnection = CurrentProject.Connection

   For Each tbl In cat.Tables
      If tbl.Type = "TABLE" Then
         If tbl.Name <> "dtproperties" Then
            Debug.Print tbl.Name
         End If
      End If
   Next tbl

End Sub
				

↑ Back to the top


Status

Microsoft Access 2000 uses ANSI standard SQL-92, which includes both queries and views in the Tables collection.

↑ Back to the top


More information

When you use the ADO object model to iterate through the Tables collection of an Access database, the names of queries will be included as part of the collection.

When you use the ADO object model to iterate through the Tables collection of an Access project, the names of views will be included as part of the collection.

Steps To Reproduce Behavior

  1. Open the sample database Northwind.mdb or the sample Access project NorthwindCS.adp.
  2. Insert a new module.
  3. On the Tools menu, click References, and select the following references if they are not already selected (checked):
      • Microsoft ActiveX Data Objects 2.1 Library
      • Microsoft ADO Ext. 2.1 for DDL and Security


  4. Type the following ADO code:
    Sub FindTables()
    
       Dim cat As New ADOX.Catalog
       Dim tbl As ADOX.Table
    
       cat.ActiveConnection = CurrentProject.Connection
    
       For Each tbl In cat.Tables
          Debug.Print tbl.Name
       Next tbl
    
    End Sub
    					
  5. Type the following line in the Immediate window, and then press ENTER:
    FindTables
    					
Note that the Immediate window lists tables, along with queries or views.

↑ Back to the top


Keywords: KB225895, kbpending, kbprb

↑ Back to the top

Article Info
Article ID : 225895
Revision : 2
Created on : 6/28/2004
Published on : 6/28/2004
Exists online : False
Views : 304