Microsoft KB Archive/174212

= FIX: ActiveForm Returns Wrong Form =

Article ID: 174212

Article Last Modified on 12/10/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Control Creation Edition
 * 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 Q174212



SYMPTOMS
When the ActiveForm property of the Screen object is queried, the wrong form is returned as the active form. This behavior occurs after setting the enabled property of a Command button on another form to False. The second form is listed as the active form, when the form with the calling code is actually the active form.



RESOLUTION
To work around this problem, insert the following line of code immediately after the code that sets the enabled property of the button: Me.SetFocus



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.



MORE INFORMATION
This behavior occurs only the first time the enabled property of the button is set to False. During subsequent attempts or if the button's enabled property is initially False, the problem does not occur.

Steps to Reproduce Behavior
 Create a new "Standard EXE" project in Visual Basic 5.0. Add an MDI form to the project. Add a standard form to the project. Set the MDI Child property of Form1 and Form2 to True. Place a Command button on Form1. Set its caption to "Disable."  Insert the following code into the Click event of this button: Form2.Command1.Enabled = False 'Me.SetFocus        'Uncomment to Workaround this Problem MsgBox Screen.ActiveForm.Name </li> Add a second Command button to Form1. Set its caption to "Enable."</li>  Insert the following code into the Click event of this button: Form2.Command1.Enabled = True </li> Add a Command button to Form2.</li>  Add the following code to the Load event of the MDI form: Form1.Show Form2.Show MDIForm1.Arrange 1 </li> Run the project, and then click the button labeled "Disable." Note that the message box displays "Form2" when the active form is actually Form1.</li> Click the button labeled "Enable," and then click the button labeled "Disable" one more time. Note that this time, "Form1" is now correctly returned as the active form.</li></ol>

Additional query words: kbVBp500bug kbVBp600fix kbVBp kbdsd kbDSupport kbVBA kbControl

Keywords: kbbug kbfix KB174212

-

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

© Microsoft Corporation. All rights reserved.