Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to loop through all queries to print SQL-text of each?

Status
Not open for further replies.

sudakov

Programmer
Jun 17, 2007
53
US
Hello everyone,
Does anyone know how to loop through all queries to print SQL-text of each?
My task is to find name of queries that use function ROUND.

I created the following code:
Code:
Public Function varSearchStringInQueries()
Dim db As Database
Dim qdf As QueryDef
Dim strSQL As String
Dim varPosition
Dim lngCounter As Long

Set db = CurrentDb()
For Each qdf In db.QueryDefs
    lngCounter = lngCounter + 1
    strSQL = qdf.SQL
    varPosition = InStr(1, strSQL, "round")
    If Nz(varPosition, 0) <> 0 Then
        Debug.Print qdf.Name
    End If
Next
Debug.Print "Number of processed queries = " & CStr(lngCounter)
End Function

However, I am getting non-expected results.

Any help is appreciated.

sudakov.
 
What does not work? I tried your code and it works fine for me.

I added a line to print the name and the SQL
Debug.Print qdf.Name
Debug.print strSql
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top