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

List the table names in a database

Status
Not open for further replies.

ranshe

Programmer
Oct 5, 2004
27
0
0
US
How can you, in VB, find the Table names that are located in a given database?
For example, say database TEST_DB contains the following tables: TableA, TableB, and TableC.
What command would return "TableA TableB TableC"?
I would like to try and implement this through VB to check if a table exists in a given database.
Any help would be great,
Thanks!
 
If you are using MSDE or SQL Server, then you could use the sp_tables stored procedure to list your tables.

Knowing the type of database you are dealing with would help to give you a solution.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Code:
    Set rs = con.OpenSchema(adSchemaTables)
    
    Do While Not rs.EOF
        Debug.Print rs("TABLE_NAME").Value
        rs.MoveNext
    Loop

The above code will work with most databases, including Access and SQL Server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top