[AccessD] Find Text In Code Programmatically

Dan Waters dwaters at usinternet.com
Tue Oct 14 12:44:00 CDT 2008


Thanks Mark - this looks interesting!

Dan

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Mark A Matte
Sent: Tuesday, October 14, 2008 12:26 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Find Text In Code Programmatically


I started a thread very similar to this about 7 months ago...I don't
remember the subject...but I wanted to do something similar.  I have a MDB I
work on every few months adding features...It will search docs for text...it
will search your computer/folder for all access databases...and store them
in a table with size, location, dates.  Another version will list all
objects in each database.

Also it will use the list of MDBs it found and search the modules(forms and
reports included) for a text string.  It has some issues with databases that
have passwords...but typically gets what I need.  I don't have a finished
product to send out...but here is the code I use to search the VBA of other
MDBs...most of this was gleaned from the web in different pieces...alot is
commented out...and not really documented.

Hope it helps,

Mark A. Matte

****************CODE*************************
Public Function ProcessExtModules(DB_Path As String)
On Error GoTo ByPassError
NoAccess = 0
Dim acc As Access.Application
MyMDB_Path = DB_Path
Set acc = New Access.Application
Set acc = fGetRefNoAutoexec(DB_Path)
'acc.OpenCurrentDatabase (DB_Path)
 If NoAccess = 1 Then GoTo Skip
ProcessModules acc
'AddDAO acc
acc.CloseCurrentDatabase
 
acc.Quit acQuitSaveNone
 
Exit Function
Skip:
DoCmd.RunSQL ("INSERT INTO tblTextFound ( fullMDBCoord, TextFound, [Module]
)SELECT '" & DB_Path & "', 'No Access', 'none';")

Set acc = Nothing
Exit Function
ByPassError:

End Function
 
Public Function ProcessModules( _
ByRef rapp As Access.Application)
On Error GoTo ShiftBypassError
Dim oVBE As Object
Dim mdl As Object
Dim blnFound As Boolean
Dim StartLine As Long
Dim StartColumn As Long
Dim EndLine As Long
Dim EndColumn As Long
'Dim MyMDB
Dim S_Text As String
S_Text = Me!txtSearch
'MyMDB = rapp.VBE.ActiveVBProject.FileName
'To make life easier and lines shorter.
Set oVBE = rapp.VBE.ActiveVBProject.VBComponents
 
'Dim s As String
's = ""
 
'Check each module ...
For Each mdl In oVBE
'*****************
        StartLine = 1
        StartColumn = 1
        EndLine = oVBE(mdl.Name).CodeModule.CountOfLines
        EndColumn = 60
        'MsgBox mdl.Name
        blnFound = oVBE(mdl.Name).CodeModule.Find(S_Text, StartLine,
StartColumn, EndLine, EndColumn)
        'if it is found. ...
        Dim nn
        nn = mdl.Name
        If blnFound = True Then
            Debug.Print oVBE(mdl.Name).CodeModule
            'MsgBox oVBE(mdl.Name).CodeModule & " Found it"
            DoCmd.RunSQL ("INSERT INTO tblTextFound ( fullMDBCoord,
TextFound, [Module] )SELECT '" & MyMDB_Path & "', '" & S_Text & "', '" &
mdl.Name & "';")

        End If
'**************
'If Len(s)> 0 Then s = s + vbCrLf
'for the required procedure ...
'Debug.Print oVBE(mdl.Name).CodeModule
's = s + oVBE(mdl.Name).CodeModule
Next
Exit Function
ShiftBypassError:
DoCmd.RunSQL ("INSERT INTO tblTextFound ( fullMDBCoord, TextFound, [Module]
)SELECT '" & MyMDB_Path & "', 'ByPassError', 'none';")

'Debug.Print s
'MsgBox s
End Function
****************CODE*************************


> From: dwaters at usinternet.com
> To: accessd at databaseadvisors.com
> Date: Tue, 14 Oct 2008 11:23:22 -0500
> Subject: [AccessD] Find Text In Code Programmatically
>
> Maybe I'm off the edge here, but I was wondering if there is a way to
enter
> a string into a text box on a form, push a button, and have the string I
> typed in found in the code?
>
> For example, I could have a list of bugs or tasks uniquely numbered. I've
> already typed Bug27 as a comment into code somewhere. When I push a button
> in the list next to Bug27 the string Bug27 is then found in code.
>
> Possible?
>
> Thanks!
> Dan
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com

_________________________________________________________________
See how Windows connects the people, information, and fun that are part of
your life.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093175mrt/direct/01/
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list