Make your own free website on Tripod.com
List All The Tables In Database (DAO)

Preparations

Add 1 List Box to your form.

Add reference to DAO:
from the menu choose Project-> References, mark the Microsoft DAO 3.6 Object Library check box, and press OK.
If you have the Microsoft DAO 3.6 Object Library reference, you can skip the text below and start copying and pasting the code to your form.

If you have only Microsoft DAO Object Library 3.51 reference or earlier, and the database you want to export made in Access 97 or earlier, You can use it instead of the 3.6 version.

Otherwise (if you using database that made in Access 2000 and you don't have Microsoft DAO 3.6 Object Library reference), click on browse, and select the file C:\Program Files\Common Files\Microsoft Shared\Dao\dao360.dll (If you have Access 2000 installed in your computer you have this file.)
This will add Microsoft DAO 3.6 Object Library reference to your project. Now mark it and press OK.

Form Code

Option Explicit
Private Sub Form_Load()
    Dim db As Database
    Dim qdef As QueryDef
    Dim td As TableDef
    Dim dbname As String

    ' Open the database. replace "c:\DBfile.mdb" with your
    ' database file name
    
   
Set db = OpenDatabase("c:\DBfile.mdb")
    ' List the table names.
   
For Each td In db.TableDefs
    ' if you want to display also the system tables, replace the line
    ' below with:  List1.AddItem td.Name

       If td.Attributes = 0 Then List1.AddItem td.Name
    Next td
    db.Close
End Sub

Go Back