Module Object, Modules Collection Example

The following example returns a reference to a Module object in the Modules collection and prints the number of lines of code in the module:

Function LinesInModule(strModuleName As String) As Long
    Dim mdl As Module

    On Error GoTo Error_LinesInModule
    ' Open module.
    DoCmd.OpenModule strModuleName
    ' Return reference to Module object.
    Set mdl = Modules(strModuleName)
    ' Return number of lines in module.
    LinesInModule = mdl.CountOfLines

Exit_LinesInModule:
    Exit Function

Error_LinesInModule:
    MsgBox Err & ": " & Err.Description
    ' If function fails, return -1.
    LinesInModule = -1
    Resume Exit_LinesInModule
End Function