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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write SQL statement to get list of tables in database

Status
Not open for further replies.

vbc22

Technical User
Dec 4, 2004
70
CA
Hi there,

Anyone know the correct syntax for writing up an SQL statement that'll return me a list of tables in a database?

I use ADO code to write SQL statements. I'd like to know what I need to write in the line where I equate the sql string.

Code:
Private Sub listDBTables()

    Dim sql As String, rst As New ADODB.Recordset
    
    sql = "SELECT fname, lname, email FROM tCustomerInfo"
    rst.Open sql, CurrentProject.Connection, adOpenKeyset
    
    ' do something with recordset object...
    
    rst.Close
    Set rst = Nothing
    
End Sub

Regards.
 
Take a look (and google if you wish) at MSysObjects.

This is a hidden table in your access database that you can query.
 
Check out the OpenSchema method of ADO.

Set rst = CurrentProject.Connection.OpenSchema(adSchemaTables)

While Not rst.EOF
If rst!table_type = "table" Then
Debug.Print rst!table_name
End If
rst.MoveNext
Wend
rst.Close
 
hi,
this should also work...

Code:
SELECT MSysObjects.Type, MSysObjects.Connect, MSysObjects.Database, MSysObjects.DateCreate, MSysObjects.DateUpdate, MSysObjects.Flags, MSysObjects.ForeignName, MSysObjects.Id, MSysObjects.Lv, MSysObjects.LvExtra, MSysObjects.LvModule, MSysObjects.LvProp, MSysObjects.Name, MSysObjects.Owner, MSysObjects.ParentId, MSysObjects.RmtInfoLong, MSysObjects.RmtInfoShort
FROM MSysObjects
WHERE (((MSysObjects.Type)=1));

easyit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top