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.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기