Access Macros  «Prev  Next»

Lesson 4 Assigning macros to controls on a form
ObjectiveAssign a macro to a command button on a form by using the command button's OnClick event.

Assigning Macros to Controls on 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.

Macro group and macro

Command Button

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 away 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.

Working With Events Macros - Quiz

Click the Quiz link below to answer a few questions about events and Macro Builders.
Working With Events Macros - Quiz

Assigning Macros to Controls Form - Exercise

Click the Exercise link below to practice actually working with events and Macro Builders.
Assigning Macros to Controls Form - Exercise