VB.net List all query name in an Access database

Murray Brown
Murray Brown used Ask the Experts™
on
Hi

What VB.net code would I use to add all the query names in an Access database to a
ComboBox. I use a connection string to connect to the Access Database

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2015
Commented:
If you add a reference to the "Microsoft Access 14.0 Object Library", or whichever version you have installed, then you should be able to open the database and loop over the queries using something like:

Module Module1

    Sub Main()
        Dim y As New Microsoft.Office.Interop.Access.Dao.DBEngine()
        Dim x As Microsoft.Office.Interop.Access.Dao.Database = y.OpenDatabase("C:\path\to\database.accdb")

        For Each query As Microsoft.Office.Interop.Access.Dao.QueryDef In x.QueryDefs
            Console.WriteLine(query.Name)
        Next

        Console.ReadKey()
    End Sub

End Module

Open in new window

Murray BrownASP.net/VSTO Developer

Author

Commented:
Thanks very much

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial