편집

다음을 통해 공유


DoCmd.SetParameter method (Access)

Use the SetParameter method to create a parameter for use by the BrowseTo, OpenForm, OpenQuery, OpenReport, or RunDataMacro methods.

Syntax

expression.SetParameter (Name, Expression)

expression A variable that represents a DoCmd object.

Parameters

Name Required/Optional Data type Description
Name Required Variant The name of the parameter. The name must match the name of the parameter expected by the BrowseTo, OpenForm, OpenQuery, OpenReport, or RunDataMacro method.
Expression Required Variant An expression that evaluates to a value to assign to the parameter.

Remarks

You must create as many calls to the SetParameter method as are necessary to create the parameters you need.

Each call to SetParameter adds or updates a single parameter in an internal parameters collection. The parameters collection is passed to the BrowseTo, OpenForm, OpenQuery, OpenReport, or RunDataMacro method. When the method is run, the parameters collection supplies the needed parameters. When the method is finished, the parameters collection is cleared.

Because each of the methods that accepts parameters clears the parameters collection when it completes, you must ensure that your calls to SetParameter immediately precede the call to the method that employs them.

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 text box is stored in the prmComment parameter. The value of the txtId text box is stored in the prmRelatedID parameter.

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.