PRB: Form No Longer Modal When Close Event CanceledArticle ID: Q129305
SYMPTOMS
RESOLUTION
MORE INFORMATION
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