ACC2002: Control OnUndo Event Does Not Fire as Expected (295184)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q295184
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SYMPTOMS

The OnUndo event of a text box or combo box does not fire when the user undoes or tries to undo changes that have been made to the data of a control.

CAUSE

The OnUndo event of the control is not triggered because the control is not in a "dirty" state.

MORE INFORMATION

For the OnUndo event of a text box or a combo box control to fire, the following conditions must be true:

  1. The control must be bound to a field.
  2. The user must manually type into the field immediately before pressing ESC.
The control must be in a specific dirty state for the OnUndo event to be triggered by pressing ESC. For either a text box or a combo box, the user must manually modify the current data by typing into the control. After the user moves the focus off the control or if the data in the control is programmatically changed, the control is no longer in a dirty state (for purposes of the OnUndo event) and the OnUndo event will not fire.

The control can be changed programmatically by several methods, including the following:

  • By clicking Undo Typing on the Edit menu.

    Undo Typing is not the same as pressing ESC and does not always restore the contents of a control to its original state. Undo Typing only undoes the last series of typing strokes, which may only be a portion of the actual modifications made since the control was first dirtied. However, because using the Undo Typing command programmatically changes a control's data, ESC will no longer trigger the control's OnUndo event.

    By selecting an option from a combo box.

    Although selecting a combo box item will fire the OnDirty event of a control, the OnUndo event will not fire even if ESC is pressed immediately afterward. Selecting from a combo box list is a programmatic change of the data because the user did not manually type into the control.
The OnUndo event of a control was intended only for specific situations where a user is directly modifying the control. Any situations that are not handled by the OnUndo event of a control may have to be handled from the OnUndo event of a form.

Steps to Reproduce the Behavior

  1. Open the sample database Northwind.mdb.
  2. Open the Customers form in Design view.
  3. Add the following code to the OnUndo event of the Country combo box control:
    Msgbox "The combo box OnUndo event has fired!"
    					
  4. Switch the Customers form to Form view, and then select another country/region from the Country combo box control.
  5. Press ESC. Note that the OnUndo event for the control does not fire.

Modification Type:MajorLast Reviewed:9/25/2003
Keywords:kbprb KB295184