Code to search all forms code

  • Thread starter Thread starter Filips Benoit
  • Start date Start date
F

Filips Benoit

Dear All,

I want to seach the code of all forms for a string.
My code below only works for open forms.
I want it to work for all forms.

See *** Problem line ****

Thanks,

Filip

***********************************************************************
Public Function SearchProjectFormsCode(ByVal strFindString As String) As
String

On Error GoTo errHandling

Dim MyForm As Object
Dim iObjectCount As Long

SearchProjectFormsCode = "String '" & strFindString & "' found in formcode:"
& Chr(13)

For Each MyForm In CurrentProject.AllForms
If FindInFormCode(MyForm.Name, strFindString) Then
SearchProjectFormsCode = SearchProjectFormsCode & Chr(13) & ">" &
MyForm.Name
iObjectCount = iObjectCount + 1
Next MyForm
SearchProjectFormsCode = SearchProjectFormsCode & Chr(13) & Chr(13) &
iObjectCount & " forms cheked!"

Exit Function

errHandling:
MsgBox Err.Number & " SearchProjectFormsCode: " & Err.Description &
Chr(13) & iObjectCount
End Function

Function FindInFormCode(strFormName As String, strSearchText As String) As
Boolean
Dim mdl As Module
Dim lngSLine As Long, lngSCol As Long
Dim lngELine As Long, lngECol As Long
Dim strLine As String, strNewLine As String
Dim intChr As Integer, intBefore As Integer, _
intAfter As Integer
Dim strLeft As String, strRight As String

Set mdl = Forms(strFormName).Module ' *** Problem line ****

If mdl.Find(strSearchText, lngSLine, lngSCol, lngELine, lngECol) Then
FindInFormCode = True
Else
FindInFormCode = False
End If

Exit_FindAndReplace:
Exit Function

Error_FindAndReplace:

MsgBox Err & " FindInFormCode: " & Err.Description
FindInFormCode = False
Resume Exit_FindAndReplace
End Function
 
You must open it in design form before having access to the code. If we
change the variable MyForm to a type of Form and use an AccessObject instead
of an Object, we get something like:

Dim objDAP As AccessObject
Dim MyForm As Form

For Each objDAP In CurrentProject.AllForms
DoCmd.OpenForm objDAP.name, acDesign

Set MyForm = Forms(objDAP.name)
...

DoCmd.Close acForm, objDAP.name, acSaveYes

Next

S. L.
 
Back
Top