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 search the queries in an Access database for a string in Visual Basic 6
DescriptionThis example shows how to use ADOX to search the queries in an Access database for a string in Visual Basic 6.
KeywordsADOX, Access, database, query, command text, search query, 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 Search 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 and searches each query's command text for the target string. If it finds the string, it lists the query's name and command text in a ListView control.

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

    MousePointer = vbHourglass
    lvwTables.ListItems.Clear
    DoEvents

    ' 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
        query = cat.Views(i).Command.CommandText
        If InStr(LCase$(query), LCase$(txtSearchFor.Text)) _
            > 0 Then
            Set list_item = _
                lvwTables.ListItems.Add(Text:=cat.Views(i).Name)
            list_item.SubItems(1) = _
                cat.Views(i).Command.CommandText
        End If
    Next i
        
    conn.Close

    MousePointer = vbDefault

    If lvwTables.ListItems.Count = 0 Then MsgBox "Done"
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated