How to list out all the procedures that exist in an MS Access Module Using VBA

This function will list out all the procedures and functions that exist in an MS Access module.

Public Function AllProcsInThisModule(ByVal strModulename As String, acc As Access.Application)
 
 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.
 'acc.DoCmd.OpenModule strModuleName
 
 ' Return reference to Module object.
 Set mdl = acc.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)
 strMsg = strMsg & intI + 1 & ". " & astrProcNames(intI) & vbCrLf
 Next intI
 
 ' Message box listing all procedures in module.
 AllProcsInThisModule = strMsg
End Function

This is a complimentary article written by the MAARS team for the MAARS user community. Code in this article drives the operation of MAARS (MS Access Application wRiting Software). MAARS is an intelligent automation program that speeds up MS Access Application Development by 10x, 20x or 100x times. To learn more about MAARS, click here.

Disclaimer:

Some information included in this article may have been sourced from other publicly available websites and blogs. In such cases, credit goes to those authors for the original ideas and thoughts, but we do take credit for putting valuable information together and improve the efficiency of other office developers.