DMW logo
tel 01732 833085
tonbridge · kent · UK

How to Use VBA to List All Modules and Macros in an Access Database

How to create VBA functions to list in the Immediate Window of its Visual Basic Editor all the modules and macros of a Microsoft® Access database.

Last updated on 2020-05-26 by David Wallis.


VBA Function to List All Modules

This function lists all the modules in the database in which you execute it:

Function dmwListAllModules() As String

On Error GoTo errHandler

Dim msg$

Dim obj As AccessObject, db As Object

Set dB = Application.CurrentProject

For Each obj In db.AllModules

Debug.Print obj.Name

Next obj

msg$ = "Module listing complete"

procDone:

dmwListAllModules = msg$

Exit Function

errHandler:

msg$ = Err.Number & " " & Err.Description

Resume procDone

End Function


VBA Function to List All Macros

Don Hirst suggested I include a function to list all macros in a database. And he kindly provided me with one. Here it is:

Function dvhListAllMacros() As String

On Error GoTo errHandler

Dim msg$

Dim obj As AccessObject, db As Object

Set dB = Application.CurrentProject

For Each obj In db.AllMacros

Debug.Print obj.Name

Next obj

msg$ = "Macros listing complete"

procDone:

dvhListAllMacros = msg$

Exit Function

errHandler:

msg$ = Err.Number & " " & Err.Description

Resume procDone

End Function

Thanks again Don.


How to Run Your Function

To execute the function, copy and paste the code into a module in your database’s Visual Basic Editor.

Then in its Immediate Window type ?NameOfFunction() and press Enter. Don’t omit the leading question mark.


Your Support for dmw TIPS

If you’re going to make use of Tips in any of your professional or commercial work, then please consider making a payment in recognition of the time spent publishing this website.

To make a contribution by PayPal in GBP (£ sterling) —

To make a contribution by PayPal in USD ($ US) —

To say how much you want to pay and to receive
a tax invoice for a GBP (£ sterling) contribution —

Invoice

Thanks, in anticipation.

SSL Cerification


Disclaimer

DMW Consultancy Ltd does not accept any liability for loss or damage to data to which any techniques, methods or code included in this website are applied. Back up your data; test thoroughly before using on live data.

“Lists are how I parse and manage the world.”

Adam Savage