Today we continue our discussion of Macros in Access. In addition to being run from the Macro Designer, macros can be assigned to controls such as Command Buttons. Command buttons are controls that you add to your form which provide you with a way of performing action(s) by simply clicking the control. To assign a macro to a Command Button, add it to the Command Button’s On Click Property. Thus, when a user clicks the button, the macro is executed.
Properties such as the On Click, On Got Focus, and On Double Click are called Events. An event is a specific action that occurs on or with a certain object. Access can respond to a variety of events such as mouse clicks, the opening or closing of forms, or changing the focus of a control. Events are usually the result of an action by a user.
To Assign a Macro to a Command Button
- Create the macro that you want to execute.
- Open the form in Design View on which you wish to add a Command Button.
- If the Use Control Wizards button is activated, click it to deactivate it.
- Click the Command Button control on the Controls group on the Design Ribbon.
- Draw the Command Button on your form until it is the desired size.
- Select the Command Button and then click the Property Sheet button.
- Click in the On Click property box.
- Click the arrow and then select the macro you want to execute when the Command button is clicked.