Validation Complications Using Form On Error

K

kiln

Access 20000/2002

Data validation error trapping can be strange. I have some fields that
are set to required and unique on the table level, for instance
ProjName. I'd like to trap for required and duplicate values.

Minimally, I usually add error trapping code to the Save button's On
Click and the form's On Error to test for Err = 3314 (required) and Err
= 3022 (dupe). This approach deals with a user tabbing off of the form
into a subform (for instance) and explicitly clicking the save button.

I don't think is copes well with the user clicking a button that moves
the focus to a subform in code, which forces a save, or if save by
shift+enter. The form On Error routine is not invoked. A "Previous
action was canceled" type message appears in the calling routine. I
could error code for that with a resume next but it seems "wrong" to
have to code for the same errors in so many places.

The only event that would seem to cover all the bases is the form before
update, which has a cancel event. But to use it I have to "know" which
fields are required and should not be dupes, and test in code to see if
the rec is safe to update. I would like to use the db engine errors if I
can, as they are fast and built in (this is Jet).

I could write a class that incorporates this sort of validation stuff
and gets involved in the form before update. But isn't there a way to
gracefully handle this with the built in stuff Access offers?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top