Solved

ADO equivalent of DAO 'Database' object

Posted on 2001-07-31
4
357 Views
Last Modified: 2013-11-23
Hi,

In the (bad) old days you could easily return the names of tables in a database through the MS Jet Workspace object.

I used to do this if I wanted the user to be able to browse for a specific table in an MS Access database...


**********************************************************
 '-- For MS Access connection
 Private wrkJet As Workspace

 Private myDB as Database
 Private myTbl As TableDef

 '-- Connect
 Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
 Set myDB = wrkJet.OpenDatabase(Database_Path, True)

 '-- Retrieve table names and show to user
 For Each myTbl In myDB.TableDefs
    ' Load to user interface here
 Next

**********************************************************

Although now I successfully use ADO to connect to SQL Server to retrieve record sets, I can not immediately see the equivalent for returning table names from an SQL Server database using the ADO connection & command objects.

Can anyone provide an example please?


Cheers!

0
Comment
Question by:G_Evans
4 Comments
 
LVL 5

Accepted Solution

by:
GeoffKell earned 200 total points
ID: 6337325
Use the OpenSchema method of the Connection object.

In example assume mdbConnection is your connection and rs is a recordset object

Regards
GK


    Set rs = mdbConnection.OpenSchema(adSchemaTables)

    Do Until rs.EOF
        If rs.Fields("TABLE_TYPE").Value = "TABLE" Or rs.Fields("TABLE_TYPE").Value = "VIEW" Then
            Debug.Print rs.Fields("TABLE_NAME").Value
        End If
        rs.MoveNext
    Loop
0
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6337367
Use ADOX to retrieve this information

Vin
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6337383
Geoff's suggestion of OpenSchema is the better way to go. ADOX adds additional components to be distributed for little benefit if this is all you want to do.
0
 

Author Comment

by:G_Evans
ID: 6337707
Cheers - as I say couldn't find an example of that in the online help - Was giving me a right headache!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now