Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse ADOX to list the queries in an Access database and give their command text in Visual Basic 6
DescriptionThis example shows how to use ADOX to list the queries in an Access database and give their command text in Visual Basic 6.
KeywordsADOX, Access, database, query, command text, Visual Basic 6
CategoriesDatabase
 
First add references to:

  • Microsoft ActiveX Data Objects 2.6 Library
  • Microsoft ADO Ext. 2.6 for DLL and Security

(Or whatever your versions are.)

When you click the List Queries button, the following code executes. It opens the database and uses the ADOX catalog to learn about the database. It loops through the Views collection (this contains the queries) adding the query names and command text to a ListView control.

 
Private Sub cmdListQueries_Click()
Dim conn As ADODB.Connection
Dim cat As ADOX.Catalog
Dim i As Integer
Dim list_item As ListItem

    lvwTables.ListItems.Clear

    ' Open the connection.
    Set conn = New ADODB.Connection
    conn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Persist Security Info=False;" & _
        "Data Source=" & txtDatabase.Text
    conn.Open

    ' Make a catalog for the database.
    Set cat = New ADOX.Catalog
    Set cat.ActiveConnection = conn

    ' List the catalog's tables.
    For i = 0 To cat.Views.Count - 1
        Set list_item = _
            lvwTables.ListItems.Add(Text:=cat.Views(i).Name)
        list_item.SubItems(1) = _
            cat.Views(i).Command.CommandText
    Next i
        
    conn.Close
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated