As you'll see in a moment, the Visual Basic 6 approach is simple and clean; it really astonishes me that it took six language versions to deliver such a lifesaver.
If Unload Mode = vb Form Control Menu Then On Error Resume Next Validate Controls If Err = 380 Then ' The current field failed validation.
Cancel = True End If End If End Sub Checking the Unload Mode parameter is important; otherwise, your application will mistakenly execute a Validate Controls method when the user clicks on the Cancel button.
On the other hand, if you typed something in the required field, the focus will now be on the second field (the numeric text box).
Try clicking on the Help or Cancel buttons: No Validate event will fire this time because you set the Causes Validation property for each of these controls to False.
Hi guys, I have some text boxes that i need to validate, for example txt this control must accept number from 1 to 31 only, if the input value is correct the focus must be sent to the next control, if it is false, must appears an error message, clear the text box and set the focus on the same text box.
I'm a little confusing about it, do you guys have an script example for it please? Set the Causes Validation() property of your Text Box(es) to True, then handle the Validating() event.
The second flaw is that the Validate event doesn't fire when you're moving the focus from a control whose Causes Validation property is False, even if the control that receives the focus has its Causes Validation property set to True.
The new Visual Basic 6 validation mechanism is simple and can be implemented with little effort.
Note that Validate Controls returns an error 380 if Cancel was set in the Validate event procedure of the control that had the focus.
Visual Basic 6's validation scheme has two flaws, though.
This is possible because they are extender features, provided by the Visual Basic runtime to all the controls placed on a form's surface.