Sub search_queries_file()
Const findtext = "sometext"
Const searchfor = 255 'use only certain types of query 255 checks all
Dim log As String
Dim fnum As Long
Dim db As database
Dim qdef As QueryDef
Dim qt As String
log = CurrentProject.path
If Right(log, 1) <> "\" Then log = log & "\"
log = log & findtext & ".txt"
fnum = FreeFile
Open log For Output As #fnum
Set db = CurrentDb
For Each qdef In db.QueryDefs
If InStr(1, qdef.SQL, findtext) > 0 Then
qt = "~~~~~"
Select Case qdef.Type
Case 0: qt = "Select"
Case 16: qt = "Crosstab"
Case 32: qt = "Delete"
Case 48: qt = "Update"
Case 64: qt = "Append"
Case 128: qt = "Union"
Case Else
qt = "??? " & qdef.Type
End Select
If (qdef.Type And searchfor) = qdef.Type Then
Print #fnum, "Type: " & qt & " " & qdef.name
End If
End If
Next
Close #fnum
On Error GoTo fail
Application.FollowHyperlink log
Exit Sub
fail:
MsgBox ("Error opening log file")
End Sub