DoCmd.RunDataMacro method (Access)
Use the RunDataMacro method to run a named data macro from Visual Basic.
expression A variable that represents a DoCmd object.
|MacroName||Required||Variant||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 by 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 text box is stored in the prmComment parameter. The value of the txtId text box 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
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.