Features and Techniques > Validation and Constraints > Using Error Event in Field Validation |
You can override the standard True DataControl error handling by providing your Error event procedure. Setting the fCancelDisplay argument to True in the Error event procedure cancels the standard message box. You can provide whatever error handling you need, including error messages and other user interaction. If you want to restore the previous field value, you can do it in the Error event calling the CancelUpdate method.
To distinguish the situation where Error event is triggered by a field validation failure, use the Source and ErrorNumber arguments. This is necessary because the Error event occurs not only on validation failures, but also on other errors, such as saving data in the database.
On a field modification failure, the Source argument is set to “TData”, and the ErrorNumber is one of the following:
For all these errors, the FieldName argument of the Error event is set to the name of the field where the failure occurred.