
DoCmd.OpenForm "Employees",, ," = 'Sales Representative'" Only employees with the title Sales Representative are included. The following example shows how you can open the Employees form in the current database. For example, the OpenForm method uses seven arguments, but only the first argument, FormName, is required. If you omit optional arguments, the arguments assume the default values for the particular method. Most of the methods of the DoCmd object have arguments some are required, while others are optional. Remarksįor example, you can use the OpenForm method of the DoCmd object to open a form, or use the Hourglass method to change the mouse pointer to an hourglass icon. An action performs tasks such as closing windows, opening forms, and setting the value of controls.


#Access visual basic examples how to#
Here we discuss how to use the ByVal argument in VBA along with the examples and downloadable excel template.You can use the methods of the DoCmd object to run Microsoft Office Access actions from Visual Basic. Things to RememberīyVal argument doesn’t affect the variable value even after running the macro, but with the By Ref argument, we can carry the value of the variable from one macro to the other. This macro carries the value of variable “k” as ten from macro “P1” to macro “P2,” and in this macro, the value will be reset to 15, but the moment it comes back to finish the macro to the first macro “P1” the value of “k” back to 10, not 15.

#Access visual basic examples code#
Now to understand “ByVal,” let’s run the VBA code line by line by pressing the F8 key. In this macro, we have used the ByVal argument to assign the value to the variable “k.” In the Macro2, we have reset the value of the variable to k = k + 5. Next, we have called the second macro procedure from the first Macro. In the first Macro, we have assigned the value of 50 to the variable “k.” Dim k As Integer Let me explain this in detail before we see the result. In the above two macro procedures, we have a common variable “k” across procedures.
