BUG: Constituent Control Validate Event Can Fail on UserControlID: Q191912
|
The Validate event of a constituent control fails to fire when you move the focus from the constituent control on a User Control to a control that is placed directly on a form.
Call the ValidateControls method from the LostFocus event of the User Control.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
The Validate event occurs before the focus shifts to a control that has its
CausesValidation property set to True. If you are moving focus between
constituent controls on a User Control, the Validate event will fire for
each control. However, if you move from a constituent control on a User
Control to a control that is placed directly on a form, the Validate event
of the constituent control on the User Control will not fire until focus
returns to a constituent control.
The workaround is to call the ValidateControls method. However, when you do
this, the LostFocus for the constituent control will fire after the
LostFocus event. This is the reverse of the normal event order.
Private Sub Text1_LostFocus()
Debug.Print "text1 lostfocus"
End Sub
Private Sub Text1_Validate(Cancel As Boolean)
Debug.Print "text1 validate"
End Sub
Private Sub Text2_LostFocus()
Debug.Print "text2 lostfocus"
End Sub
Private Sub Text2_Validate(Cancel As Boolean)
Debug.Print "text2 validate"
End Sub
Private Sub UserControl_ExitFocus()
' The On Error is needed because if the Validate returns a
' False then you will receive error 380 on the ValidateControls.
' To cause the Validate event to fire when you move the focus
' from the constituent control to a control on the form, uncomment
' the following two lines:
'On Error Resume Next
'ValidateControls
End Sub
Private Sub UserControl_Initialize()
UserControl.BackColor = RGB(0, 0, 255)
End Sub
Private Sub Text1_LostFocus()
Debug.Print "form1 text1 lost focus"
End Sub
Private Sub Text1_Validate(Cancel As Boolean)
Debug.Print "form1 text1 validate"
End Sub
Private Sub UserControl11_LostFocus()
ValidateControls
End Sub
Additional query words: kbDSupport kbDSD kbVBp kbVBp600bug kbCtrlCreate
Keywords :
Version :
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: June 9, 1999