Module: Macros in Category Microsoft Access : Macros and Modules from Total Visual SourceBook

Retrieving Microsoft Access macro names and running them in Access VBA.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the modMacros module.
MacroNamesToArray Procedure Loads an array with the names of all the macros in the current database.
MacroNamesToString Procedure Populate a string with the names of all the macros in the current database.
RunAMacro Procedure Run a macro and trap for errors. If an error occurs while running the macro, a value of False is returned. If no errors occur, a value of True is returned. For more advanced use, you use the full syntax of the DoCmd RunMacro command: Syntax: DoCmd RunMacro MacroName, RepeatCount, RepeatExpression where:
  • RepeatCount - the number of times to run the macro
  • RepeatExpression - when this becomes false, the macro stops repeating
' Example of modMacros
' To try this example, do the following:
' 1. Create a new form in your copy of Sample.mdb (in the Total Visual SourceBook sample directory).
' 2. Create a command button 'cmdTest'
' 3. Paste this code into the form's module

Private Sub Form_Open(Cancel As Integer)
  cmdTest.Caption = "Test Access macro functions"
End Sub

Private Sub cmdTest_Click()
  Dim astrNames() As String
  Dim strNames As String
  Dim intCount As Integer
  Dim intCounter As Integer

  ' Example of MacroNamesToArray
  intCount = MacroNamesToArray(astrNames)
  Debug.Print "Macro Names:"
  For intCounter = 0 To intCount - 1
    Debug.Print intCounter & ": " & astrNames(intCounter)
  Next intCounter

  ' Example of MacroNamesToString
  intCount = MacroNamesToString(strNames, ";")
  Debug.Print "Macro Names: " & strNames

  ' Example of RunAMacro
  RunAMacro "Macro1"

End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!

View all FMS products for Microsoft Access All Our Microsoft Access Products


Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info




Free Product Catalog from FMS