Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tables In an Access Database 1

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
How would I retrieve a list (to be entered into a list box) of all the tables contained within a particualr Access databse. I can find loads of examples of operation when connected to a particular table but nothing for getting a list of tables itself.

thanks

elziko
 
elziko,

Look at the tabledefs collection in Ms. Access. Just enumerate the collection with the name property:

For each Tbl in db.Tabledefs
[tab]Debug.print tbl.Name[tab][tab][tab][tab]'Replace w/ your instruction
Next Tbl

MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
With DAO :

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

Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX
Source CodeBook for the programmer
 
edderic,

I tried your code. I know nothing about DAO. Is your code supposed to work on its own? The compiler complains that the user types are not defined. I've obviously missed the point here. What now???!

thanks

elziko
 
You need to put a referense to DAO for the code to work. (Project|References|Microsoft DAO)

Good Luck
-Mats
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top