Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Listing Tables Using ADO or DAO

Posted on 2005-04-19
3
Medium Priority
?
239 Views
Last Modified: 2010-05-02
Hello,

Ive been contracted to write a program to update the data structures and tables of an Access database when the client deploys an updated version of their software.  This will run initially and upgrade the database with the latest fields and tables as required.

However, im a little stumped as to how to read the table names from the MDB file.  I cannot use constants for the table names in this case as the client will be using this program on several other projects as well.

Is there a way to list the tables of an Access database using either ADO or DAO, or is there perhaps another method which I am overlooking?

Thanks for your help.
0
Comment
Question by:Lethal_J
3 Comments
 
LVL 28

Assisted Solution

by:vinnyd79
vinnyd79 earned 400 total points
ID: 13819226
0
 
LVL 13

Accepted Solution

by:
rettiseert earned 600 total points
ID: 13819260
This is another way with DAO:

    Dim db As DataBase
    Dim tbldef As TableDef
    Dim fld As Field
   
    Set db = OpenDatabase("C:\path\your_db.mdb")
   
    For Each tbldef In db.TableDefs
        If Left(tbldef.Name, 4) <> "MSys" Then
            Debug.Print tbldef.Name
            For Each fld In tbldef.Fields
                Debug.Print vbTab + fld.Name
            Next
        End If
    Next
0
 
LVL 1

Expert Comment

by:Doodle
ID: 13822336
The following code will list all the object name from the msysobjects table all you will need to do is create an connection to the db.

Public Sub listtablenames()
    Dim RS As New ADODB.Recordset
    RS.Open "Select * from msysobjects", CN
        Do Until RS.EOF
            Debug.Print RS("Name")
            RS.MoveNext
        Loop
    RS.Close
End Sub
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question