BUG: ActiveForm Returns Wrong Form

Last reviewed: September 25, 1997
Article ID: Q174212
The information in this article applies to:
  • Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions for Windows, version 5.0

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. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

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

  1. Create a new "Standard EXE" project in Visual Basic 5.0.

  2. Add an MDI form to the project.

  3. Add a standard form to the project.

  4. Set the MDI Child property of Form1 and Form2 to True.

  5. Place a Command button on Form1. Set its caption to "Disable."

  6. 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
    
    

  7. Add a second Command button to Form1. Set its caption to "Enable."

  8. Insert the following code into the Click event of this button:

          Form2.Command1.Enabled = True
    

  9. Add a Command button to Form2.

  10. Add the following code to the Load event of the MDI form:

          Form1.Show
          Form2.Show
          MDIForm1.Arrange 1
    

  11. Run the project, and then click the button labeled "Disable." Note that

        the message box displays "Form2" when the active form is actually
        Form1.
    

  12. 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.
    
Keywords          : VBKBCtrl VBKBInt VBKBObj VBKBVB
Version           : WINDOWS:5.0
Platform          : WINDOWS
Issue type        : kbbug


================================================================================


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.

Last reviewed: September 25, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.