Understanding Access 2003's Event Repertoire When you interact with an object by using the keyboard or the mouse, you can change the object's state. The object's state is stored with the other data about the object. Access makes some of the changes in the object's state available as opportunities to interrupt normal processing. These special changes in an object's state are called events. An event is a change in the state of an object at which you can interrupt normal processing and define a response. The best way to understand events is to categorize each by the type of action that causes the event to occur. There are 11 categories: Mouse events are triggered when you click form objects. Keyboard events are triggered by forms and form controls when you type or send keystrokes with the SendKeys action while the Form object has the focus. Window events are triggered by opening or closing forms or reports. Focus events are triggered when a form or form control gains or loses the focus or when a form or report becomes active or inactive. Data events are triggered by forms and form controls when you change data in controls or records, or by forms when the record pointer moves from one record to another. Filter events are triggered by forms when you apply or remove filters. Print events are triggered by reports and report sections when you print or preview a report. Error events are triggered by a form or report that has the focus when an error occurs. Timing events are triggered by forms when a specified time interval passes. Class module events fire when you open or close an instance of a class. You use the With Events qualifier to intercept events from ActiveX Data Objects (ADO) and the RaiseEvent command to define custom events. Reference events fire when you add or remove a reference to an object or type library in the References collection. Table 28.1 groups Access 2003's events according to their source. Table 28.1. Events Grouped by CauseEvent Category | Source | Events |
---|
Mouse | The user creating mouse actions | Click DblClick MouseDown MouseUp MouseMove MouseWheel | Keyboard | The user typing on the keyboard or SendKeys sending keystrokes | KeyDown KeyUp KeyPress | Window | Opening, closing, or resizing a window Load | Open load Unload Close Resize | Focus | An object losing or gaining the focus, or a form or report becoming active or inactive | Enter GotFocus Exit LostFocus Activate Deactivate | Data | Making changes to a control's data, displaying records in a form, or moving the focus from one record to another in a form | Current BeforeInsert AfterInsert Delete BeforeDelConfirm AfterDelConfirm BeforeUpdate AfterUpdate Change Updated Dirty NotInList Undo* | Filter | Opening or closing a filter window, or applying or removing a filter | Filter ApplyFilter | Print | Selecting or arranging data for printing | Format Print Retreat NoData Page | Error | Generating an error | Error | Timing | A specified period of time expiring | Timer | Class Module | Opening a new instance of class module or terminating an instance of class module | Initialize Terminate | Reference | Adding or removing a reference to an object or type library | ItemAdded ItemRemoved | Access 2000 added the Dirt event (and Dirty property) of bound forms. The Dirty event fires and the Dirty property is set to True when you change underlying data by typing in a bound text box or combo box, or change a page by clicking a Tab control. The Dirty event doesn't fire if you change a value with code, nor does it fire for any action on an unbound form. Moving the mouse wheel repeatedly triggers Access 2003's MouseWheel event. The Undo event is the reverse of the Dirty event; returning data in the form to its original, unmodified state fires the Undo event. | Each event that an object triggers has a corresponding event property listed in a separate category of the object's property sheet. Usually the corresponding event property is the event name preceded by the word "On"; for example, the Click event triggered by a command button becomes the On Click property in the button's property sheet. Figure 28.19 shows the Event page of the property sheet for a text box displaying the 17 events that the text box control can trigger. Notice that all event properties except the Before Update and After Update data event properties follow the pattern of preceding the event name with "On". Access 2002 added the On Dirty and On Undo events for controls. | Figure 28.19. Text boxes fire 17 events. Access 2002 added the On Dirty and On Undo events to bound controls. The On MouseWheel event doesn't apply to text boxes. Note | Events for PivotCharts and PivotTables arrived with Access 2002. These 17 new events appear at the end of the Events page of the Form properties window, and apply only to PivotChart and PivotTable views. Two of the events, On Connect and On Disconnect, retain the "On" prefix in their event handler names, OnConnect and OnDisconnect, which is inconsistent with other events. |
|