1
votes

I am trying to improve my error handling code.

Using Access (2007) VBA:

When an error occurs in the forms On Error handler the variable DataErr gives me the error code but I have no access to the Err object.

Access to the Err object allows me to parse the error description and give a detailed custom message (eg error code 3314 exactly which field is causing the error) to the user

How can I have access to the Err object from the form's OnError handler? Not only the error code

Note: I can access the Err object from code attached to the "save" and "delete" buttons on my form and give customised messages for duplicate keys, missing required fields, linked reecords that can not be deleted,etc.

This works fine if the user clicks these button. But if the user decides to select the next or previous row - which causes a save to occur - my code is not called and the user gets shown the standard MS Access error message

1
Form errors are not the same as VBA or DAO errors, AFAIK: msdn.microsoft.com/en-us/library/ff836345.aspx - Fionnuala
@Remou Great answer, pity it's a comment or I could have upvoted. - Matt Donnan
@Matt thanks, but it was so short and mainly link, so I thought it was against the rules for answers. - Fionnuala

1 Answers

1
votes

"if the user decides to select the next or previous row - which causes a save to occur - my code is not called and the user gets shown the standard MS Access error message"

Use the form's Before Update and Before Insert events to validate the current values. If any are unacceptable, you can assign True to the procedure's Cancel parameter, and notify the user about invalid values.