|< Day Day Up >|
Access forms are the place where your database's users interact directly with the Jet engine. And as such, they are also the places where many things can go wrong. Users might enter data that violates a validation rule, or try to create records with duplicate primary keys, or cause a referential integrity problem.
As you probably already know, Jet is the underlying database engine of Access the part of the application that actually saves and retrieves data.
None of these errors can be trapped directly in VBA, because VBA does not get involved between the Access user interface and the Jet engine. But there is still a hook to let your VBA code get involved if you like: the Form's Error event is called whenever the Jet engine is ready to process a data error of any kind. If you like, you can react to this error to amplify or override Jet's default error message. Here's how:
Whenever a Jet error occurs during data entry, Access calls the VBA event handler for the form's Error event. This handler has two arguments. The DataErr argument is the number of the Jet error that triggered the event. In this case, you're looking for event 2113, which corresponds to invalid data. The Response argument is one that you can set when you're done dealing with the error. If you set this argument to the constant acDataErrDisplay, Access displays its own default error message. If you set this argument to the constant acDataErrContinue, Access suppresses its own default error message.
There's no master list of Jet errors. But you can set up a skeletal event handler with a breakpoint in it, and then check the value of DataErr in the Immediate window, to determine the error numbers of the errors that you want to deal with.
|< Day Day Up >|