Assign a macro to a command button on a form by using the command button's OnClick event.
Assigning Macros to Controls on a Form
Macros are really useful when you assign the macros to events on the different objects in Access.
An example of this would be when you click a command button, a number of events are fired or occur.
The event used most often with the command button control is the OnClick event. The OnClick event fires when a user clicks the command button.
To assign events to forms, reports, and controls, go to the Event tab of the property sheet for that object. Refer to the figure below, which shows a macro group and macro created in the last lesson assigned to an event.
As you can see, there are quite a few events even with a command button.
With other controls, such as the Text Box control, you will have additional events called BeforeUpdate and AfterUpdate.
These events are useful for running macros when a user updates data in the control. Forms and reports have additional events that fire off when the form or report is opened (OnOpen, OnLoad) and closed (OnClosed, OnUnLoad).
There is a way to find out which events are used on which objects.
Creating a form with a number of command buttons on it, and using their OnClick events with macros to open forms, is a great way to create a switchboard.
In the next lesson, you will learn how to run different types of queries by using macros.