Microsoft KB Archive/177163

= FIX: Focus Doesn't Return to MDI Form After Modal Form Is Closed =

Article ID: 177163

Article Last Modified on 11/18/2003

-

APPLIES TO


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

-



This article was previously published under Q177163



SYMPTOMS
An MDI child form shows a second non-MDI form modally. The second form displays a message box (or another modal form). When you close the second form after dismissing the message box, the focus does not return to the MDI child form as expected. The focus returns to the MDI child form only when the second form does not display a message box (or a modal form).



RESOLUTION
To work around this problem, set the focus to the MDI child form after you've shown the non-MDI child. The workaround is illustrated in the MORE INFORMATION section of this article.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Basic 6.0.



Steps to Reproduce Behavior
 Start a new Standard EXE project in Visual Basic. Form1 is created by default. From the Form1 properties dialog box, set the MDIChild property to True. From the Project menu, click Add MDI Form to display the Add MDI Form dialog box. Click Open to add an MDI Form to the project. Add a second form to the project. Add a CommandButton to each of the forms.  Copy the following code to the code window of Form1: Option Explicit

Private Sub Form_Load Command1.Caption = "Show Modal Form" End Sub

Private Sub Command1_Click Form2.Show vbModal 'Uncomment the following statement to work around the problem 'Me.SetFocus End Sub   Copy the following code to the code window of the Form2 form: Option Explicit

Private Sub Form_Load Command1.Caption = "Show Message Box." End Sub

Private Sub Command1_Click MsgBox "Displayed from the non-MDI form." End Sub </li> Press the F5 key to run the program, and then complete the following steps:

<ol> Click Show Modal Form in the MDI Child form and the second form appears.</li> Click Show Message Box in the second form and the message box appears (a message box is modal).</li> Click OK in the message box to close the message box.</li> Close the second form.</li></ol>

Results: Focus does not return to the MDI child form as expected.</li></ol>

Additional query words: kbVBp500bug kbVBp600fix kbVBp kbdsd kbDSupport kbMDI

Keywords: kbbug kbfix KB177163

-

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

© Microsoft Corporation. All rights reserved.