Form Search

Jerry8989

Registered User.
Local time
Yesterday, 22:12
Joined
Mar 16, 2006
Messages
64
I'm trying to create a find that will search through all my forms and let me know where a specific control is. I have it working if the forms are open but I can't open every form to run the find. Does anyone know of a way I can search all the controls on the forms to find where a specific control is?
 
Code

' Forms
For i = 0 To CurrentProject.AllForms.Count - 1
fName = CurrentProject.AllForms(i).Name
bOpen = CurrentProject.AllForms(i).IsLoaded
If Not bOpen Then
DoCmd.OpenForm fName, acNormal
End If
If Forms(fName).Module.Find(sFind, StartLine, StartColumn, EndLine, EndColumn) Then
Debug.Print "Form " & fName
End If

For j = 0 To Forms(fName).Controls.Count - 1
cName = Forms(fName).Controls.Item(j).Name
If InStr(1, cName, sFind, vbTextCompare) > 0 Then
Debug.Print "Form " & fName & " Control: " & cName
End If
Next j

If Not bOpen Then
DoCmd.Close , fName, acSaveNo
End If

Next


The problem with this code is it opens all the forms which includes subforms then it errors out. I wish there was a way to search all forms and the VBA code without opening the forms.
 
Hello:
Your on the right track. What you need to do is nest your control check routine within your form check routine. Then after the first form is loaded and check for the control name, You need to issue a command to close that current form. Your code would then procedure to the next form to check.

Regards
Mark
 

Users who are viewing this thread

Back
Top Bottom