How to find all the Queries in an MS Access Database using VBA

This procedure finds all the Queries in an MS Access Database. This prints out the name of each query plus the SQL behind each query.

Public Sub AllQueryDefs()
    Dim obj As QueryDef, dbs As DAO.Database
    Set dbs = CurrentDb
    For Each obj In dbs.QueryDefs
        
            If InStr(obj.Name, "~") = 0 Then
                Debug.Print obj.Name & " SQL - " & obj.SQL & vbNewLine & " ----------- " & vbNewLine
            End If
            

    Next obj
End Sub

This is a complimentary article written by the MAARS team for the MAARS user community. Code in this article drives the operation of MAARS (MS Access Application wRiting Software). MAARS is an intelligent automation program that speeds up MS Access Application Development by 10x, 20x or 100x times. To learn more about MAARS, click here.

Disclaimer:

Some information included in this article may have been sourced from other publicly available websites and blogs. In such cases, credit goes to those authors for the original ideas and thoughts, but we do take credit for putting valuable information together and improve the efficiency of other office developers.