You want to programmatically write the SQL statement from all saved queries
to file(s)?
Loop through the QueryDefs of the CurrentDb.
Possibly skip those with a name starting with ~.
Open a file for output.
Print # the SQL property of each QueryDef in the loop.
Close the file.
You will need some understanding of VBA code to implement this.
A rudimentary example follows:
Function DumpQueries() As String
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Const strcFile = "C:\MyQueries.txt"
Open strcFile For Output As #1
Set db = CurrentDb
For Each qdf In db.QueryDefs
If Not qdf.Name Like "~*" Then
Print #1, qdf.Name & ": " & Trim$(Replace(qdf.SQL, vbCrLf, " "))
End If
Next
Close #1
Set qdf = Nothing
Set db = Nothing
DumpQueries = strcFile
End Function
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.