ACC: Cannot Close Form from Control's OnExit Property

Last reviewed: August 29, 1997
Article ID: Q115574
The information in this article applies to:
  • Microsoft Access versions 2.0, 7.0, 97

SYMPTOMS

Novice: Requires knowledge of the user interface on single-user computers.

When you try to close a form from one of the following:

  • the OnExit, OnEnter, OnLostFocus, or OnGotFocus property of a control on the form

    -or-

  • the OnCurrent property of the form

you receive the error message:

   This action can't be run while processing a form or report event.

CAUSE

A macro or procedure that closes the active form is called from a control's OnExit, OnEnter, OnLostFocus, or OnGotFocus property.

RESOLUTION

To work around this problem, add a new control containing a flag to the form. Then, refer to that flag's value before closing the form, as demonstrated in the following example:

  1. To the form in question, add a new, unbound text box control.

  2. Set the new control's Name property to FlagControl. Set its DefaultValue property to 0.

  3. Set the OnExit property of the control from which you want to close the form to the following event procedure:

          Me![FlagControl]=-1
    

    To create this event procedure, click the OnExit property field, click the Build button to the right of the field, and then select Code Builder. After you enter the code, close the module.

  4. On the Edit menu, click Select Form.

  5. Set the form's TimerInterval property to 500.

  6. In Microsoft Access 7.0 and 97, set the form's OnTimer property to the following event procedure:

          If Me![FlagControl] Then
    
                DoCmd.Close
             End If
    
       In Microsoft Access 2.0, set the form's OnTimer property to the
       following event procedure:
    
          If Me![FlagControl] Then
             DoCmd Close
          End If
    
    

  7. View the form in Form view, and then exit the control (either by pressing TAB or by clicking another control).

STATUS

Microsoft has confirmed this to be a problem in Microsoft Access 2.0, 7.0, and 97. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Problem

  1. Set the OnExit property of any control on a form to the event procedure:

          DoCmd.Close (in Microsoft Access 2.0 type DoCmd Close)
    

  2. View the form in Form view, and then exit the control (either by pressing TAB or by clicking another control).
Keywords          : kberrmsg kbprg PgmOthr FmsEvnt
Version           : 2.0 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbbug
Solution Type     : kbworkaround


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.