Getting all tables in a database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to retrieve all the tables which are there in an access database and
put them in a combo box
 
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.
 
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
 
Back
Top