DoCmd.RunDataMacro Method (Access)

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

Version Information

Version Added: Access 2010

Syntax

expression .RunDataMacro(MacroName)

expression A variable that represents a DoCmd object.

Parameters

Name

Required/Optional

Data Type

Description

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").

Remarks

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.

Example

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 

See Also

Concepts

DoCmd Object Members

DoCmd Object