Link to home
Start Free TrialLog in
Avatar of grayghost69
grayghost69

asked on

Write VBA that will search through other VBA code

I am trying to write a VBA tool within a form, that will search through all of the VBA code within all forms and modules for a specific string.  This would be like using the Find tool, only using VBA to initiate it.

I was thinking that I could just reference the Find tool, but I couldn't find how to do that.

This is in Access 97
Avatar of joekendall
joekendall
Flag of United States of America image

You would need to create a Module object and set it to the module you want to search. Then, you would need to use the Find method of the Module object to find a specific string.

Thanks!

Joe
Avatar of grayghost69
grayghost69

ASKER

I think it would help if I could see an example of how it would load each of the forms from the forms collection, then search it.
Here is the code that I am using to read each of the forms in currently.

Sub Search()
    Dim db As Database
    Dim cont As Container
    Dim frm As Document
   
    Set db = CurrentDb()
    Set cont = db.Containers("Forms")
   
    For Each frm In cont.Documents
        str = frm.Name
        MsgBox str
    Next frm
End Sub
ASKER CERTIFIED SOLUTION
Avatar of joekendall
joekendall
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Run the sub tryme() and it will print all of your form names to the debug window and whether they contain the string "EnumWindows" or not. You can change the "EnumWindows" to the string you want to find.

Thanks!

Joe
That's close enough to what I need.  I got the part answered that I needed, thank.
Close enough to what I need, I can manipulate it to my purposes.  

Thanks,
Brian
Glad to help!

Thanks!

Joe