An Access event is the result or consequence of some user action. An Access event occurs when a user moves from one record to another in a form, closes a report, or clicks on a command button on a form. Even moving the mouse generates a continuous stream of events.
Access applications are event-driven and Access objects respond to many types of events. Access events are hooked into specific object properties. For example, checking or unchecking a check box triggers a MouseDown, a MouseUp, and a Click event. These events are hooked into the check box through the OnMouseDown, OnMouseUp, and OnClick properties, respectively. You use VBA to compose event procedures that run whenever the user clicks on the check box.
Access events can be categorized into seven groups:
- Windows (form, report) events: Opening, closing, and resizing
- Keyboard events: Pressing or releasing a key
- Mouse events: Clicking or pressing a mouse button
- Focus events: Activating, entering, and exiting
- Data events: Changing the current row, deleting, inserting, or updating
- Print events: Formatting and printing
- Error and timing events: Happening after an error has occurred or some time has passed
In all, Access supports more than 50 different events that can be harnessed through VBA event procedures.
Of these types of events, by far the most common are the keyboard and mouse events on forms. As you'll see in the following sections, forms and most controls recognize keyboard and mouse events. In fact, exactly the same keyboard and mouse events are recognized by forms and controls. The code you write for a mouse-click event on a command button is exactly the same sort of code that you might write for the mouse-click on a form.
In addition, most Access object types have their own unique events. The following sections discuss the most commonly programmed events, but Microsoft has a habit of introducing new event capabilities with each new version of Access. Also, many ActiveX controls you might use in your Access applications may have their own unique and special events. When using an unfamiliar control or a new type of object in your Access applications, be sure to check out what events and properties are supported by the control or object.