Article ID: 223131
Article Last Modified on 5/13/2003
APPLIES TO
- Microsoft Visual Basic 6.0 Learning Edition
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Visual Basic 6.0 Enterprise Edition
This article was previously published under Q223131
SYMPTOMS
A Visual Basic 6.0 project contains two forms with Form1 containing a TextBox and a CommandButton. The LostFocus event of the TextBox displays a second form as modal. When you run the project and click the CommandButton, the modal form appears and the CommandButton Click event fires, but should not.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
This bug was corrected in Visual Studio 6.0 Service Pack 3. For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base:
194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why
194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed
MORE INFORMATION
Steps to Reproduce Behavior
- Start a new Standard EXE project in Visual Basic. Form1 is created by default.
- From the Project menu, click Add Form, and then click Open. Form2 is added to your project.
- Add a TextBox and a CommandButton to Form1.
Copy the following code to the Code window of Form1:
Option Explicit Private Sub Command1_Click() Debug.Print "Command1_Click" End Sub Private Sub Form_Load() Text1.Text = "" Text1.TabIndex = 0 End Sub Private Sub Text1_LostFocus() Debug.Print "Text1_LostFocus" If Text1.Text = "" Then Form2.Show vbModal End If End Sub
- With the Immediate Window visible, run the project. On the Run menu, select Start, or press the F5 key to start the program. Click the CommandButton.
BUG: The Text1 LostFocus event followed by the CommandButton Click event is fired.
The expected behavior is for the Text1 LostFocus event to fire but the Command1 Click event should not.
REFERENCES
A similar bug behavior is documented in the following article in the Microsoft Knowledge Base:
223101 FIX: WriteProperties Event Executes at Wrong Time
For more information, see the following topics:
Add Form Command (Project Menu) in the Online Help or the MSDN Web site at http://msdn.microsoft.com/library/devprods/vs6/vb/html/vbcmdforminsert.htm (how to add a form to a project).
LostFocus Event in the Online Help or the MSDN Web site at http://msdn.microsoft.com/library/devprods/vs6/vb/html/vbevtlostfocus.htm (explains the LostFocus event).
Keywords: kbbug kbfix kbactivexevents kbvs600sp3fix KB223131