Peter Hallett said:
Perish the thought that I should be seen to be soliciting more free
software
(but then, on the other hand, I was never one to look a gift horse in the
mouth!) I will watch this space with interest.
Code posted at the bottom of this message. Warning: this has been only
lightly tested, and is very rough indeed!
As a footnote to the double-dotted syntax, discussed in the last post,
your
original text arrived on my machine showing both stops, which were then,
as
you observed, reproduced in all subsequent copies. Strangely, the problem
only showed itself where the same code was split. There were other lines
which wrapped without apparent difficulty. Bit of a mystery.
It's very odd. I suspect some fault in Microsoft's forum software. The
double dots don't show up in Google Groups, either.
Here are procedures to search VBA code. Again, watch out for line-wrapping.
'------ start of code ------
Sub SearchVBA(strSought As String, Optional bWholeWord As Boolean)
' Search all VBA code -- in standard, class, form, and report modules --
' for the specified string.
' Copyright (c) 2009, Dirk Goldgar and DataGnostics, LLC
' You may copy and use this code all you want, so long as
' you preserve the copyright and this notice, and don't
' sell it.
On Error GoTo Err_Handler
SearchModules strSought, bWholeWord
SearchFormModules strSought, bWholeWord
SearchReportModules strSought, bWholeWord
Exit_Point:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point
End Sub
Function SearchModule( _
mdl As Access.Module, _
strSought As String, _
Optional bWholeWord As Boolean) _
As Long
' Search module <mdl> for string <strSought>.
' Optional argument <bWholeWord> tells whether to report only
' occurrences of the string as a "whole word".
' Copyright (c) 2009, Dirk Goldgar and DataGnostics, LLC
' You may copy and use this code all you want, so long as
' you preserve the copyright and this notice, and don't
' sell it.
On Error GoTo Err_SearchModule
Dim bFound As Boolean
Dim lngFoundCount As Long
Dim lngStartLine As Long
Dim lngEndLine As Long
Dim lngStartCol As Long
Dim lngEndCol As Long
Dim lngProcType As Long
lngFoundCount = 0
lngStartLine = 0
lngEndLine = 0
With mdl
Do
lngEndLine = 0
lngStartCol = 0
lngEndCol = 0
bFound = .Find(strSought, lngStartLine, lngStartCol, lngEndLine,
lngEndCol, bWholeWord)
If bFound Then
lngFoundCount = lngFoundCount + 1
Debug.Print "Found in " & _
IIf(mdl.Type = acStandardModule, "standard", "class") &
_
" module " & .Name & ", line " & lngStartLine & ", proc
'" & .ProcOfLine(lngStartLine, lngProcType) & "'"
lngStartLine = lngStartLine + 1
End If
Loop While bFound
End With
Exit_SearchModule:
SearchModule = lngFoundCount
Exit Function
Err_SearchModule:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_SearchModule
End Function
Sub SearchModules(strSought As String, Optional bWholeWord As Boolean)
' Search all standard and class modules for the specified string.
' Copyright (c) 2009, Dirk Goldgar and DataGnostics, LLC
' You may copy and use this code all you want, so long as
' you preserve the copyright and this notice, and don't
' sell it.
On Error GoTo Err_SearchModules
Dim db As DAO.Database
Dim cnt As DAO.Container
Dim doc As DAO.Document
Dim mdl As Access.Module
Dim bFound As Boolean
Dim lngSearchCount As Long
Dim lngFoundCount As Long
Dim lngStartLine As Long
Dim lngEndLine As Long
Dim lngStartCol As Long
Dim lngEndCol As Long
Dim lngProcType As Long
Dim bOpenedModule As Boolean
Debug.Print "*** Searching standard and class modules for '" & strSought
& "' ..."
Set db = CurrentDb
Set cnt = db.Containers("Modules")
For Each doc In cnt.Documents
lngSearchCount = lngSearchCount + 1
If CurrentProject.AllModules(doc.Name).IsLoaded = False Then
DoCmd.OpenModule doc.Name
bOpenedModule = True
Else
bOpenedModule = False
End If
Set mdl = Modules(doc.Name)
lngStartLine = 0
lngEndLine = 0
lngFoundCount = lngFoundCount + SearchModule(mdl, strSought,
bWholeWord)
If bOpenedModule = True Then
DoCmd.Close acModule, mdl.Name, acSaveNo
End If
Set mdl = Nothing
Next doc
Exit_SearchModules:
Set cnt = Nothing
Set db = Nothing
Debug.Print "*** Searched " & lngSearchCount & _
" modules, found " & lngFoundCount & " occurrences."
Exit Sub
Err_SearchModules:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_SearchModules
End Sub
Sub SearchFormModules(strSought As String, Optional bWholeWord As Boolean)
' Search the class modules of all forms that have them,
' looking for the specified string.
' Copyright (c) 2009, Dirk Goldgar and DataGnostics, LLC
' You may copy and use this code all you want, so long as
' you preserve the copyright and this notice, and don't
' sell it.
On Error GoTo Err_SearchFormModules
Dim db As DAO.Database
Dim doc As DAO.Document
Dim frm As Access.Form
Dim mdl As Access.Module
Dim lngFormCount As Long
Dim lngFoundCount As Long
Dim bOpenedForm As Boolean
Debug.Print "*** Searching form modules for '" & strSought & "' ..."
Set db = CurrentDb
For Each doc In db.Containers("Forms").Documents
If CurrentProject.AllForms(doc.Name).IsLoaded = False Then
DoCmd.OpenForm doc.Name, acDesign, WindowMode:=acHidden
bOpenedForm = True
Else
bOpenedForm = False
End If
Set frm = Forms(doc.Name)
With frm
If frm.HasModule Then
lngFormCount = lngFormCount + 1
lngFoundCount = lngFoundCount + SearchModule(frm.Module,
strSought, bWholeWord)
End If
If bOpenedForm Then
DoCmd.Close acForm, .Name, acSaveNo
End If
End With
Set frm = Nothing
Next doc
Exit_SearchFormModules:
Set doc = Nothing
Set db = Nothing
Debug.Print "*** Searched " & lngFormCount & _
" forms, found " & _
lngFoundCount & " occurrences."
Exit Sub
Err_SearchFormModules:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_SearchFormModules
End Sub
Sub SearchReportModules(strSought As String, Optional bWholeWord As Boolean)
' Search the class modules of all reports that have them,
' looking for the specified string.
' Copyright (c) 2009, Dirk Goldgar and DataGnostics, LLC
' You may copy and use this code all you want, so long as
' you preserve the copyright and this notice, and don't
' sell it.
On Error GoTo Err_SearchReportModules
Dim db As DAO.Database
Dim doc As DAO.Document
Dim rpt As Access.Report
Dim mdl As Access.Module
Dim lngReportCount As Long
Dim lngFoundCount As Long
Dim bOpenedReport As Boolean
Debug.Print "*** Searching report modules for '" & strSought & "' ..."
Set db = CurrentDb
For Each doc In db.Containers("Reports").Documents
If CurrentProject.AllReports(doc.Name).IsLoaded = False Then
DoCmd.OpenReport doc.Name, acDesign, WindowMode:=acHidden
bOpenedReport = True
Else
bOpenedReport = False
End If
Set rpt = Reports(doc.Name)
With rpt
If rpt.HasModule Then
lngReportCount = lngReportCount + 1
lngFoundCount = lngFoundCount + SearchModule(rpt.Module,
strSought, bWholeWord)
End If
If bOpenedReport Then
DoCmd.Close acReport, .Name, acSaveNo
End If
End With
Set rpt = Nothing
Next doc
Exit_SearchReportModules:
Set doc = Nothing
Set db = Nothing
Debug.Print "*** Searched " & lngReportCount & _
" reports, found " & _
lngFoundCount & " occurrences."
Exit Sub
Err_SearchReportModules:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_SearchReportModules
End Sub
'------ end of code ------