How to find all the Modules in an MS Access databases using VBA

This procedure finds all the modules in an MS Access Database. This shows how many modules are in the database and prints out the number of lines of code the module has as well as the code in that module.

Public Sub AllModules()
    Dim obj As AccessObject, dbs As Object, mdl As Module
    Set dbs = Application.CurrentProject
    ' Search for open AccessObject objects in AllModules collection.
    MsgBox dbs.AllModules.Count
    For Each obj In dbs.AllModules
        Set mdl = Modules(obj.Name)
            Debug.Print obj.Name & mdl.CountOfLines & vbNewLine & mdl.Lines(1, mdl.CountOfLines)
           
    Next obj
End Sub

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.