Results 1 to 12 of 12

Thread: ADO - Table Collection

  1. #1

    Thread Starter
    Lively Member MileOut's Avatar
    Join Date
    Nov 2001
    Location
    Glasgow
    Posts
    83

    ADO - Table Collection

    I'm trying to use ADO instead of DAO for accessing an MS Access Database but I can't find anything remotely similar to the DAO.TableDefs collection.

    Basically, what I want to do is list all the tables within the aforementioned database in a listbox.

    Any ideas?
    Last edited by MileOut; Feb 8th, 2004 at 09:47 AM.
    Talk History Forum - Discussing the past...

  2. #2
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

  3. #3
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    Heres a short example.


    VB Code:
    1. 'Add a reference to Microsoft ADO Ext. 2.x
    2.  
    3. Dim objConn As New ADODB.Connection
    4. Dim objAdox As New ADOX.Catalog
    5. Dim TB As ADOX.Table
    6. objConn.Open strConnectionString
    7. objAdox.ActiveConnection = objConn
    8.  
    9. List1.Clear
    10. For Each TB In objAdox.Tables
    11.     List1.AddItem TB.Name
    12. Next
    13.  
    14. objConn.Close
    15. Set objConn = Nothing

    Last edited by veryjonny; Feb 9th, 2004 at 01:24 AM.

  4. #4

    Thread Starter
    Lively Member MileOut's Avatar
    Join Date
    Nov 2001
    Location
    Glasgow
    Posts
    83
    Thank you both. That's exactly what I need.
    Talk History Forum - Discussing the past...

  5. #5
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    Welcome

  6. #6

    Thread Starter
    Lively Member MileOut's Avatar
    Join Date
    Nov 2001
    Location
    Glasgow
    Posts
    83
    Further to the Tables collection, I'd now like to get the Fields collection.

    I've found something through ADOX called the Columns collection which I'm guessing is the equivalent. I can't, however, seem to get a list of a table's fields into a listbox.

    Any further solutions?
    Talk History Forum - Discussing the past...

  7. #7
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    VB Code:
    1. Dim objConn As New ADODB.Connection
    2. Dim objAdox As New ADOX.Catalog
    3. Dim TB As ADOX.Table
    4. Dim Col As ADOX.Column
    5. objConn.Open ConnectionString
    6. objAdox.ActiveConnection = objConn
    7.  
    8. List1.Clear
    9. Set TB = objAdox.Tables("TableName")
    10. For Each Col In TB.Columns
    11.     List1.AddItem Col.Name
    12. Next
    13. objConn.Close
    14. Set objConn = Nothing


  8. #8
    Addicted Member
    Join Date
    Feb 2004
    Location
    Milwaukee, Wisconsin, USA
    Posts
    133
    How about listing the Access Query names and the fields that are used in each Query using ADOX ???

  9. #9
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    VB Code:
    1. Dim P As ADOX.Procedure
    2. For Each P In objAdox.Procedures
    3.     List1.AddItem P.Name
    4. Next

    Just fingure around with this, maybe u might even get the fields involved

  10. #10
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    Here's a little more comprehensive example I made

    http://www.1337geek.com/code/vb6/database/ADODB/
    If wishes were fishes we'd all cast nets.

  11. #11

    Thread Starter
    Lively Member MileOut's Avatar
    Join Date
    Nov 2001
    Location
    Glasgow
    Posts
    83
    This is all good - I can now navigate through all the tables and put all their fields into a listbox but I can't seem to dimension an ADOX.Table and then set it to the name of the table chosen in the listbox

    Whenever I try (snippet):

    VB Code:
    1. Dim tbl As ADOX.Table
    2. Set tbl = Catalog.Tables(MyListBox)

    I get an error regarding not being able to find the item within the collection based on the ordinal.
    Talk History Forum - Discussing the past...

  12. #12
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    What are u trying?

    trying to get a reference of the selected table?

Posting Permissions

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



Click Here to Expand Forum to Full Width