Solved

ADO equivalent of DAO 'Database' object

Posted on 2001-07-31
4
347 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

708 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

15 Experts available now in Live!

Get 1:1 Help Now