Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

DoCmd.RunDataMacro Method (Access)

Use the RunDataMacro method to run a named data macro from Visual Basic.

Version Added: Access 2010

expression .RunDataMacro(MacroName)

expression A variable that represents a DoCmd object.




Data Type





Name of the saved macro. The name must include the name of the table to which the data macro is attached (for example, "Comments.AddComment").

Use the RunDataMacro method to reuse a named data macro in Visual Basic code.

If the data macro requires parameters, you must first create them using the SetParameter method prior to calling the RunDataMacro method. Each call to SetParameter creates a single named parameter.

The following code example creates two parameters for use by the AddComment data macro. The two parameters are named prmComment and prmRelatedID, respectively. The value of the txtComment textbox is stored in the prmComment parameter. The value of the txtId textbox is stored in the prmRelatedID parameter. The "Comments.AddComment" data macro is then run.

Private Sub cmdAddComment_Click() 
DoCmd.SetParameter "prmComment", Me.txtComment 
DoCmd.SetParameter "prmRelatedID", Me.txtId 
DoCmd.RunDataMacro "Comments.AddComment" 
End Sub 

© 2015 Microsoft