Identifying Common Events
Certain events are raised by many different Access objects. Microsoft has taken great care that these events behave exactly the same way, regardless of the object raising them. Table below lists several of the events most commonly used by Access developers. Most of these events apply to forms and all the different controls you might add to an Access form.
Table-1: Events Common to Multiple Object TypesEven | Event Type | When the Event Is Triggered |
---|---|---|
Click | Mouse event | When the user presses and releases (clicks) the left mouse button on an object |
DblClick | Mouse event | When the user presses and releases (clicks) the left mouse button twice on an object |
MouseDown | Mouse event | When the user presses the mouse button while the pointer is on an object |
MouseMove | Mouse event | When the user moves the mouse pointer over an object |
MouseUp | Mouse event | When the user releases a pressed mouse button while the pointer is on an object |
MouseWheel | Keyboard event | When the user spins the mouse wheel |
KeyDown | Keyboard event | When the user presses any key on the keyboard when the object has focus or when the user uses a SendKeys macro action |
KeyUp | Keyboard event | When the user releases a pressed key or immediately after the user uses a SendKeys macro action |
KeyPress | Keyboard event | When the user presses and releases a key on an object that has the focus or when the user uses a SendKeys macro action |
Not surprisingly, these events are all associated with the mouse and the keyboard because these are the user's primary means of inputting information and giving directions to an application. Not every object responds to every one of these events, but when an object responds to any of these events, the event exhibits exactly the same behavior.
Tip: Many developers simply copy and paste VBA code from one event procedure to the same event procedure on another object. For example, you might want to do some fancy formatting on a text box when the user clicks into the box. You can copy the code performing the fancy formatting into another control's Click event procedure to get the same effect without having to retype the code. Even though you'll have to fix up the pasted code with the second text box's name, it's much less work than retyping the entire procedure.
Access supports many, many different events. In fact, one of Access's fundamental strengths is the wide variety of events available to developers. You can control virtually every aspect of an Access application's behavior and data management through event procedures. Although Microsoft makes no formal distinction between types of events, the following sections categorize events and event procedures into groups based on the type of object (forms, reports, and so on) that raise the events within the group.
Tip: Access supports a very, very rich event model. Not many Access developers master every Access event, nor is there need to. Virtually every Access developer learns and uses the events that are important for the applications he's building and then learns other events as he goes. You don't need to worry about memorizing all these events - instead, just be aware that Access supports many different types of events and that they're there when you need them.