They work together as follows: When the input focus leaves a control, Visual Basic checks the Causes Validation property of the control that is about to receive the focus.If this property is True, Visual Basic fires the Validate event in the control that's about to lose the focus, thus giving the programmer a chance to validate its contents and, if necessary, cancel the focus shift. Imagine that you have five controls on a form: a required field (a Text Box control, txt Required, that can't contain an empty string), a numeric field, txt Numeric, that expects a value in the range 1 through 1000, and three push buttons: OK, Cancel, and Help.
The error provider simply takes a control and a message in the Set Error method and does the rest of the work for you!
You do not have to disable the Form’s Auto Validate property.
However, I prefer to call it explicitly and handle all validation at once since you most likely will take action only if the entire control’s children pass validation. The most important thing to recognize here is how precise you can be with the validation error message in the error provider.
Instead, click on the OK button to execute the Validate event of the numeric field, where you can check it for invalid characters and valid range.
1000 Then Cancel = True End If If Cancel Then Msg Box "Please enter a number in range [1-1000]", vb Exclamation End If End Sub In some circumstances, you might want to programmatically validate the control that has the focus without waiting for the user to move the input focus.