Getting all tables in a database

A

Alok

I want to retrieve all the tables which are there in an access database and
put them in a combo box
 
D

Douglas J. Steele

SELECT MSysObjects.Name
FROM MSysObjects
WHERE MSysObjects.Name Not Like "msys*" AND MSysObjects.Type=1
ORDER BY MSysObjects.Name;

That'll only return tables that are actually in your MDB. If you want to
find linked tables as well, you'll need to use MSysObjects.Type IN (1, 6)
and, for tables linked through ODBC, the Type is 4.
 
P

PaulaB

If you're talking about listing the items in a combo box
on a form, here is a sample from a database application
which I'm programming right now. Hope this helps.

Private Sub Form_Load()
Dim dbs As Database, tbl As TableDef
Dim X(100), strList As String
Dim Y As Integer

Set dbs = CurrentDb

For Y = 0 To dbs.TableDefs.Count - 1
Set tbl = dbs.TableDefs(Y)
X(Y) = tbl.Name

Next Y

For Y = 0 To dbs.TableDefs.Count - 1
If Y = dbs.TableDefs.Count - 1 Then
strList = strList & X(Y)
Else
strList = strList & X(Y) & ";"
End If
Next Y
cboTables.RowSource = strList
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top