Hi guys,
Sorry for delay in getting back, did some skiing today (last runs of the season
)...
I have made some changes based on the updates here and some code I founf on MS's help site, but still running into problems; I think is due to the attempt to loop through the AllModules collection then getting the other one (Modules) to actually set the object. It runs OK for the first module then it says it cannot find the next one.
I'll try some more a bit later but here is what I have for now.
Code:
Public Sub ListProceduresInAllModules() 'tah college
Dim modl As Module
Dim lineNum As Long
Dim procName As String
'Dim obj As AccessObject
Dim i As Integer, sModule As String
'For Each obj In Application.CurrentProject.AllModules 'type mismatch **************
For i = (Application.CurrentProject.AllModules.Count - 1) To 0 Step -1
sModule = Application.CurrentProject.AllModules.Item(i).Name
Set modl = Application.Modules(sModule)
'Debug.Print "Module: " & modl.Name
WRITE_ERROR_RESULTS ("Module: " & modl.Name)
AllProcs (sModule)
' lineNum = 1
' Do While lineNum < modl.CountOfLines
' procName = modl.ProcOfLine(lineNum, vbext_pk_Proc)
' If procName <> "" Then
' 'Debug.Print " Procedure: " & procName
' WRITE_ERROR_RESULTS ("Procedure: " & procName)
' End If
' lineNum = modl.ProcStartLine(procName, vbext_pk_Proc) + _
' modl.ProcCountLines(procName, vbext_pk_Proc)
' Loop
Next i
End Sub
Public Function AllProcs(ByVal strModuleName As String)
Dim mdl As Module
Dim lngCount As Long
Dim lngCountDecl As Long
Dim lngI As Long
Dim strProcName As String
Dim astrProcNames() As String
Dim intI As Integer
Dim strMsg As String
Dim lngR As Long
' Open specified Module object.
DoCmd.OpenModule strModuleName
' Return reference to Module object.
Set mdl = Modules(strModuleName)
' Count lines in module.
lngCount = mdl.CountOfLines
' Count lines in Declaration section in module.
lngCountDecl = mdl.CountOfDeclarationLines
' Determine name of first procedure.
strProcName = mdl.ProcOfLine(lngCountDecl + 1, lngR)
' Initialize counter variable.
intI = 0
' Redimension array.
ReDim Preserve astrProcNames(intI)
' Store name of first procedure in array.
astrProcNames(intI) = strProcName
' Determine procedure name for each line after declarations.
For lngI = lngCountDecl + 1 To lngCount
' Compare procedure name with ProcOfLine property value.
If strProcName <> mdl.ProcOfLine(lngI, lngR) Then
' Increment counter.
intI = intI + 1
strProcName = mdl.ProcOfLine(lngI, lngR)
ReDim Preserve astrProcNames(intI)
' Assign unique procedure names to array.
astrProcNames(intI) = strProcName
End If
Next lngI
strMsg = "Procedures in module '" & strModuleName & "': " & vbCrLf & vbCrLf
For intI = 0 To UBound(astrProcNames)
WRITE_ERROR_RESULTS (" Procedure: " & strProcName)
'strMsg = strMsg & astrProcNames(intI) & vbCrLf
Next intI
' Message box listing all procedures in module.
'MsgBox strMsg
End Function
Public Sub WRITE_ERROR_RESULTS(sResult As String)
Dim strLogPath As String, strCurrentMonth As String
Dim iFile As Integer, strLOG As String
On Error Resume Next
strCurrentMonth = CStr(DatePart("yyyy", Date)) & "_" & CStr(DatePart("m", Date))
'get application path
strLogPath = Application.CurrentProject.Path
'open file
iFile = FreeFile
strLOG = strLogPath & "\" & strCurrentMonth & "_" & "VBA_PROCEDURES.TXT"
Open strLOG For Append As iFile
'write the result line
Print #iFile, sResult
'close file
Close iFile
End Sub
Cheers,