Hi Kevin,
This is an interesting idea. Here is what I came up with.
The idea is to export the modules as code, parse the procedures and save
them in a record.
Arvin has some code that will export each module as a text file:
http://www.accessmvp.com/Arvin/DocDatabase.txt
I modified Arvin's code to just export the modules code. Then, I created a
new mdb and a table.
I named the table "tblCode".
The fields in the table are:
ID Autonumber
txtSubFunc Text 'Function or Sub
txtName Text 'Procedure name
mCode Memo 'the code
To parse the text files, I came up with this code:
(could be attached to a button)
'*********************************************************
Option Compare Database
Option Explicit
Public Sub ParseTextFile()
Dim d As DAO.Database
Dim rs As DAO.Recordset
Dim k As Integer
Dim t As Integer
Dim FileName As String ' Name of text file to process
Dim InputString As String ' input string
Dim ProcName As String ' name of function
Dim subSTR As String
Dim FuncSubType As String
Dim IsFuncSub As Boolean ' is this the start of a proc
Dim paren As Long
Dim f As Long
Set d = CurrentDb
'open the recordset
Set rs = d.OpenRecordset("tblCode")
'----------------------------------------------------------------------
'could read all of the text file names into an array
' then loop thru them
FileName = "D:\docs\modules\Test_mod.txt"
'----------------------------------------------------------------------
' open the text file
k = FreeFile
Open FileName For Input As #k
'loop thru each line of the text file
Do While Not EOF(k)
IsFuncSub = False
'read line
Line Input #k, InputString
InputString = Trim(InputString)
'check for start of Function or Sub
If InStr(1, InputString, "Function ") > 0 Then
FuncSubType = "Function"
f = InStr(1, InputString, "Function") + 9
IsFuncSub = True
ElseIf InStr(1, InputString, "Sub ") > 0 Then
FuncSubType = "Sub"
f = InStr(1, InputString, "Sub") + 4
IsFuncSub = True
End If
'is this the start of a Sub or Function?
If IsFuncSub Then
'get function name
paren = InStr(1, InputString, "(")
ProcName = Mid(InputString, f, paren - f)
'insert a new record
rs.AddNew
rs.Fields("txtSubFunc") = FuncSubType
rs.Fields("txtName") = ProcName
rs.Fields("Mcode") = InputString & vbCrLf
'loop thru the rest of the procedure
Do
Line Input #k, InputString
rs.Fields("Mcode") = rs.Fields("Mcode") & InputString & vbCrLf
Loop Until Trim(InputString) = "End " & FuncSubType
rs.Update
End If
Loop
'clean up
Close #k
rs.Close
Set rs = Nothing
Set d = Nothing
End Sub
'******************************************************
Additional modifications to the code:
~ Error handler code
~ Read all of the text file names into an array and loop thru them; delete
the files when all files have been processed
~ Read all of the MDBs into an array, link/import the Modules, then export
the code, unlink, process text files
HTH