Microsoft KB Archive/129305

From BetaArchive Wiki

PRB: Form No Longer Modal When Close Event Canceled

Article ID: Q129305
Creation Date: 24-APR-1995
Revision Date: 19-SEP-1996 The information in this article applies to:

  • Microsoft Access version 1.1

SYMPTOMS


When you open two forms as modal forms and then cancel the Close event for the top form with a macro or function, both forms are no longer modal. You can switch from one form to the other. When you close the top form, the bottom form becomes modal again.

RESOLUTION


If you need to have two modal forms open and you need to have the Close event canceled for one of the forms, upgrade to Microsoft Access version 2.0. The behavior described above does not occur in Microsoft Access version 2.0.

MORE INFORMATION


Steps to Reproduce Behavior


 1. Open a new Microsoft Access database.

 2. Create a new module and add the following line to the Declarations
    section:

       Option Explicit

 3. Enter the following code in the module:

       Function BeforClosing()
        If forms!Form1!canClose=0 Then
           DoCmd CancelEvent
           DoCmd SelectObject a_form, "form1"
        End If
        End Function

        Function CloseMe()
           Dim curForm as Form
           Set curForm = screen.activeform
           curForm![CanClose] = 1
           DoCmd Close a_form, "form1"
        End Function

 4. Create a new blank form and set its Modal property to Yes. Save the
    form as Form1.

 5. Add a text box to the Form1 form and set the following properties:

       Name: CanClose
       DefaultValue: 0

 6. Add a command button to the form and set the following property:

       OnPush: =closeMe()

 7. Set the following property for the Form1 form:

       OnClose: =beforClosing()

 8. Close the Form1 form.

 9. Create a second new blank form and set the Modal property to Yes. Save
    the form as Form2.

Close the Form2 form.

Create the following macro to open the two forms:

       MacroName     Action
       ----------------------
       Macro1        OpenForm
                     OpenForm

       Macro1 Actions
       -------------------
       OpenForm
          Form Name: Form2
       OpenForm
          Form Name: Form1

Save the macro as Macro1.

Run the Macro1 macro to open the two modal forms.

Try to close the Form1 form by double-clicking the Control-menu box in
    the upper-left corner of the form. Repeat the attempt to close the
    Form1 form. Note that the two forms are no longer modal. You can
    switch from one form to the other.

Close the Form1 form by choosing the command button on the Form1 form.
    Note that the Modal property has returned to the Form2 form.



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.

©1997 Microsoft Corporation. All rights reserved. Legal Notices.


Additional reference words: 1.10
KBCategory: kbusage
KBSubcategory: FmsEvnt