View Full Version : Searching through Queries


LEXLUTH0R
05-15-2008, 03:23 PM
I have a rather extensive Microsoft Access Database. I am
overwhelmed by 1000’s of tables, queries and forms that I have built over the years. I’m looking for a tool or utility that will help me search them so that I can find what I am looking for. Please Help. Thank you in advance.

boblarson
05-15-2008, 03:46 PM
I have a rather extensive Microsoft Access Database. I am
overwhelmed by 1000’s of tables, queries and forms that I have built over the years. I’m looking for a tool or utility that will help me search them so that I can find what I am looking for. Please Help. Thank you in advance.

The free V-Tools Total Deep Search will find anything as far as your database structure goes, if that's what you want.
http://www.skrol29.com/dev/en_vtools.htm

As for searching the data, that is one thing I don't believe it will do, if that was what you were talking about.

LEXLUTH0R
05-16-2008, 07:29 AM
The free V-Tools Total Deep Search will find anything as far as your database structure goes, if that's what you want.
http://www.skrol29.com/dev/en_vtools.htm

As for searching the data, that is one thing I don't believe it will do, if that was what you were talking about.


:) Right on topic (perhaps my description needed some work but you nailed it. I will try that out. Thanks a lot!

Guus2005
05-16-2008, 08:01 AM
In the past i used MZTools for this purpose, but i can't install anything on my customers computer. So i have written it myself, It also includes code to change a fieldname in all your queries when you change a table fieldname.Public Sub SearchInQueryDefs(strSearch As String)

Dim qdf As QueryDef
Dim qdfs As QueryDefs
Dim blnFound As Boolean

Set qdfs = CurrentDb.QueryDefs

For Each qdf In qdfs
blnFound = InStr(1, qdf.SQL, strSearch) > 0
If blnFound Then
Debug.Print "Searching : " & qdf.Name & "...";
Debug.Print " - found"
If vbNo = MsgBox("Found!" & vbCrLf & vbCrLf & "" & strSearch & " found in " & qdf.Name & vbCrLf & vbCrLf & qdf.SQL & "" & vbCrLf & vbCrLf & "Confirm to continue, Decline to cancel the search", vbExclamation + vbYesNo, "SearchInQueryDefs") Then
Exit Sub
End If
End If
Next qdf

MsgBox "Done searching.", vbInformation

End Sub
Public Sub ReplaceInQueryDefs(strSearch As String, strReplace As String)
'Run this command in your immediate window (control-g)
'Replace a string in all query definitions
'Example: ReplaceInQueryDefs "U_ParentID", "ParentID"

Dim qdf As QueryDef
Dim qdfs As QueryDefs
Dim strSql As String

Set qdfs = CurrentDb.QueryDefs

For Each qdf In qdfs
strSql = qdf.SQL
If InStr(1, strSql, strSearch) > 0 Then
qdf.SQL = Replace(strSql, strSearch, strReplace)
Debug.Print "Replaced in query : " & qdf.Name
If vbNo = MsgBox("Found!" & vbCrLf & vbCrLf & "String replaced in " & qdf.Name & _
vbCrLf & vbCrLf & qdf.SQL & "" & _
vbCrLf & vbCrLf & "Confirm to continue, Decline to cancel", _
vbExclamation + vbYesNo, "ReplaceInQueryDefs") Then
Exit Sub
End If
End If
Next qdf

MsgBox "Done replacing in queries.", vbInformation

End SubHTH:D

LEXLUTH0R
05-16-2008, 08:08 AM
Thanks Guus, however, I am not that sophisticated and do not know how I would add that code to my database and actually use it. I need a turn key solution.

In the past i used MZTools for this purpose, but i can't install anything on my customers computer. So i have written it myself, It also includes code to change a fieldname in all your queries when you change a table fieldname.Public Sub SearchInQueryDefs(strSearch As String)

Dim qdf As QueryDef
Dim qdfs As QueryDefs
Dim blnFound As Boolean

Set qdfs = CurrentDb.QueryDefs

For Each qdf In qdfs
blnFound = InStr(1, qdf.SQL, strSearch) > 0
If blnFound Then
Debug.Print "Searching : " & qdf.Name & "...";
Debug.Print " - found"
If vbNo = MsgBox("Found!" & vbCrLf & vbCrLf & "" & strSearch & " found in " & qdf.Name & vbCrLf & vbCrLf & qdf.SQL & "" & vbCrLf & vbCrLf & "Confirm to continue, Decline to cancel the search", vbExclamation + vbYesNo, "SearchInQueryDefs") Then
Exit Sub
End If
End If
Next qdf

MsgBox "Done searching.", vbInformation

End Sub
Public Sub ReplaceInQueryDefs(strSearch As String, strReplace As String)
'Run this command in your immediate window (control-g)
'Replace a string in all query definitions
'Example: ReplaceInQueryDefs "U_ParentID", "ParentID"

Dim qdf As QueryDef
Dim qdfs As QueryDefs
Dim strSql As String

Set qdfs = CurrentDb.QueryDefs

For Each qdf In qdfs
strSql = qdf.SQL
If InStr(1, strSql, strSearch) > 0 Then
qdf.SQL = Replace(strSql, strSearch, strReplace)
Debug.Print "Replaced in query : " & qdf.Name
If vbNo = MsgBox("Found!" & vbCrLf & vbCrLf & "String replaced in " & qdf.Name & _
vbCrLf & vbCrLf & qdf.SQL & "" & _
vbCrLf & vbCrLf & "Confirm to continue, Decline to cancel", _
vbExclamation + vbYesNo, "ReplaceInQueryDefs") Then
Exit Sub
End If
End If
Next qdf

MsgBox "Done replacing in queries.", vbInformation

End SubHTH:D