|
Passing Multiple Values to Access Forms with the OpenArgs ParameterProvided by: Steve Clark, Senior Project ManagerTip Usage: Microsoft Access - Beginner to Intermediate VBA DeveloperIf you would like to pass one or more parameters to a form in Microsoft Access, you can use the OpenArgs parameter of the DoCmd Object to send them. The OpenArgs parameter is a string that the form can read once it is opened. Calling the form, add the string to the OpenArgs Parameter like the following: DoCmd.OpenForm "frmName", OpenArgs:="Parameter(s)" One real-life example would be to set default values for controls on a form being opened. Suppose that you have a form of Product Categories, and the user needs to enter a new product for the category. You could open the Product entry form and then default the category value for them. With the following parameter, you could default the Category combo box to the current value. For example: DoCmd.OpenForm "frmName", OpenArgs:="cboCategory|" & txtCategoryID. which may result in a value such as "cboCategory|123" In the Load event of the Form, you would need to add code to parse the information that is being received in the OpenArgs. In this example, we are using two values, separated by the 'Pipe' (|) character. The code in the form would need to find the existence of the Pipe character, then extract the first and second words, then make the assignment. For example:
|