DoCmd.SetParameter (Access)

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

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.

SetParameter (Name, Expression)


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

Arguments

The following arguments are required:

Name (String) - 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 - An expression that evaluates to a value to assign to the parameter