Microsoft KB Archive/197128

= BUG: CausesValidation Property Does Not Trigger Validate Event =

Article ID: 197128

Article Last Modified on 3/7/2005

-

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 Q197128



SYMPTOMS
The Validate event of a control is not executed when it loses focus to another control that has its CausesValidation property set to True.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
Microsoft Visual Basic 6.0 introduced a new Boolean property called CausesValidation on various controls, such as the TextBox. According to Visual Basic Help, when there is an attempt to put focus on a control that has its CausesValidation property set to True, the Validate event of the control that is losing focus executes. During that Validate event, you can verify that the data entered is valid and you can prevent the shift of focus to the new control if you want.

Steps to Reproduce Behavior
 Create a new Standard EXE project. Form1 is created by default. Add three TextBox controls to Form1. Set the CausesValidation property in Text1 and Text3 to True. Set the CausesValidation property in Text2 to False.  Paste the following code into Form1: Private Sub Text1_Validate(Cancel As Boolean) Debug.Print "Text1's Validate Event" End Sub

Private Sub Text2_Validate(Cancel As Boolean) Debug.Print "Text2's Validate Event" End Sub

Private Sub Text3_Validate(Cancel As Boolean) Debug.Print "Text3's Validate Event" End Sub  Run the sample project.</li> The focus begins on Text1. Click Text3. The CausesValidation property of Text3, set to True, causes the Validate event of Text1 to be executed as expected.</li> With the focus on Text3, click Text2. The CausesValidation property of Text2, set to False, does not cause the Validate event of Text3 as expected.</li> With the focus on Text2, click Text3. The CausesValidation property of Text3, set to True, does not cause the Validate event of Text2 as it should.</li></ol>

With the CausesValidation property of Text2 set to False, there does not appear to be any way to get a Validate event for Text2 to execute.

Aside from attempting to use the LostFocus event to manually call a Validate event for Text2 from Text2, you can work around this problem by changing the CausesValidation property from False to True.

Additional query words: kbdsd Causes Validation

Keywords: kbbug kbctrl kbpending kbactivexevents KB197128

-

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

© Microsoft Corporation. All rights reserved.