Microsoft KB Archive/189617

= PRB: Infinite Loop if Modal Form Shown in MDIChild's QueryUnload =

Article ID: 189617

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q189617



SYMPTOMS
When attempting to close an MDI parent form, the application gets caught in an infinite loop of showing a modal form.



CAUSE
When the MDI parent form is closed, the QueryUnload events of all MDI child forms are called. If any one of these MDI child forms displays a modal form during this event, such as prompting to save information, the infinite loop is initiated.

This behavior will not occur if the MDI child form is closed before the MDI parent is closed.



RESOLUTION
To work around this problem, explicitly unload the MDI child form in either the QueryUnload event of that MDI child or in the QueryUnload event of the MDI parent.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Create a new Standard EXE project. Form1 is created by default. From the Project menu, add an MDI form, MDIForm1, to the project. Set the MDIChild property of Form1 to True. From the Project menu, add another form, Form2, to the project.  Paste the following code into Form1's QueryUnload event: Form2.Show vbModal </li> Run the project.</li> Attempt to close MDIForm1 without closing Form1 first. The QueryUnload event of Form1 fires in an infinite loop and Form2 is displayed repetitively.</li>  Change Form1's QueryUnload event to be: Form2.Show vbModal Unload Form1 </li> Repeat steps 6 and 7. The application closes as desired.</li></ol>

Additional query words: kbDSupport kbDSD kbVBp kbVBp500 kbMDI kbVBp600

Keywords: kbprb KB189617

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.