Part II: Programming Microsoft Access
466
l (^) When text changes in a text box or in the text-box portion of a combo box: KeyDown
→ KeyPress → Change → KeyUp
l (^) When a value that is not present in the drop-down list is entered into a combo box’s
text area: KeyDown → KeyPress → Change → KeyUp → NotInList → Error
l (^) When data in a control is changed and the user presses Tab to move to the next
control:
Control1: KeyDown → BeforeUpdate → AfterUpdate → Exit → LostFocus
Control2: Enter → GotFocus → KeyPress → KeyUp
l (^) When a form opens and data in a control changes: Current (form) → Enter
(control) → GotFocus (control) → BeforeUpdate (control) → AfterUpdate
(control)
l When a record is deleted: Delete → BeforeDelConfirm → AfterDelConfirm
l (^) When the focus moves to a new blank record on a form and a new record is created
when the user types in a control: Current (form) → Enter (control) → GotFocus
(control) → BeforeInsert (form) → AfterInsert (form)
l Mouse events
l (^) When the user presses and releases (clicks) a mouse button while the mouse pointer is
on a form control: MouseDown → MouseUp → Click
l (^) When the user moves the focus from one control to another by clicking the second
control:
Control1: Exit → LostFocus
Control2: Enter → GotFocus → MouseDown → MouseUp → Click
l (^) When the user double-clicks a control other than a command button: MouseDown →
MouseUp → Click → DblClick → MouseUp
Writing simple form and control event procedures
Writing simple procedures to verify a form or control’s event sequence is quite easy. Use the preced-
ing information to determine which event should be harnessed in your application. Very often unex-
pected behavior can be traced to an event procedure attached to an event that occurs too late — or
too early! — to capture the information that is needed by the application.
The Chapter12.accdb example database includes a form named frmEventLogger that prints
every event for a command button, a text box, and a toggle button in the Debug window. This
form is provided to demonstrate just how many Access events are triggered by minor actions. For
example, clicking the command button one time, and then tabbing to the text box and pressing
one key on the keyboard fires the following events:
l cmdButton_MouseDown
l (^) cmdButton_MouseUp