Events: Making your database objects work together

Events: Making your database objects work together

What is an event?

An event is a specific action that occurs on or with a certain object. Microsoft Access can respond to a variety of events: mouse clicks, changes in data, forms opening or closing, and many others. Events are usually the result of user action.

By using either an event procedure or a macro, you can add your own custom response to an event that occurs on a form, report, or control.

Suppose you want a Product Details form to open when you click a Product Details command button on an Orders form. The following examples show how to do this either by using an event procedure or by using a macro.

Responding to a Click event by using an event procedure

When you create an event procedure for an object, Access adds an event procedure template named for the event and the object to the form or report module. All you need to do is add code that responds in the way you want when the event occurs for the form or report.

Create a command button event

Place methods in event procedures to carry out actions

Responding to a Click event by using a macro

To have a macro run in response to an event, open the property sheet for the form, report, or control. Find the property that corresponds to the event, and set it to the macro you want to run.

Create a macro linked to an event

For a complete list of events, click .

For information on running a macro or an event procedure from an event on a form, report, or control, click .