Group:  Microsoft Access ยป microsoft.public.access.odbcclientsvr
Thread: How best to trap for errors, things like required fields that are null?

How best to trap for errors, things like required fields that are null?
mat <mat[ at ]notarealdotcom.adr> 10/3/2008 5:33:11 PM
Is there any systematic way in which one can handle odbc data errors on
Access 2003 forms? sql 2005 is the backend.

Example is if a user does not enter a value into a required field in a
subform. If they click the save button, which runs code to save the
record, I can trap for error 3146. But if the user clicks outside the
subform, and Access tries to save the record, I can't find any way to
intercept the error. Surprisingly the form_error event does not fire.

The error can be handled using the form before_update, and trapping for
errors at the save command but it's not very elegant. Any suggestions?
Re: How best to trap for errors, things like required fields that are null?
mat <mat[ at ]notarealdotcom.adr> 12/3/2008 3:26:36 PM
In article <MPG.234ff731c992e60098972c[ at ]msnews.microsoft.com>,
mat[ at ]notarealdotcom.adr says...
[Quoted Text]
> Is there any systematic way in which one can handle odbc data errors on
> Access 2003 forms? sql 2005 is the backend.
>
> Example is if a user does not enter a value into a required field in a
> subform. If they click the save button, which runs code to save the
> record, I can trap for error 3146. But if the user clicks outside the
> subform, and Access tries to save the record, I can't find any way to
> intercept the error. Surprisingly the form_error event does not fire.
>
> The error can be handled using the form before_update, and trapping for
> errors at the save command but it's not very elegant. Any suggestions?
>
bump?
Re: How best to trap for errors, things like required fields that are null?
"Ray Jefferson" <ray[ at ]databasewhiz.com> 12/21/2008 10:13:47 PM
Your thought is correct, to use the BeforeUpdate event. However, rather than
attempting to trap the error, check to see if the user has entered fields
you already know require data. i.e.

If IsNull(Me.LastName) then
Msgbox "You must enter last name.", vbInformation, "Missing Data"
Me.LastName.SetFocus
Cancel = True
End If

...and so on for each field that is required. This way, the error is
never generated and you have informed the user beforehand in language they
understand that required fields are missing.


RJ
Database Whiz Consulting
www.databasewhiz.com


"mat" <mat[ at ]notarealdotcom.adr> wrote in message
news:MPG.234ff731c992e60098972c[ at ]msnews.microsoft.com...
[Quoted Text]
> Is there any systematic way in which one can handle odbc data errors on
> Access 2003 forms? sql 2005 is the backend.
>
> Example is if a user does not enter a value into a required field in a
> subform. If they click the save button, which runs code to save the
> record, I can trap for error 3146. But if the user clicks outside the
> subform, and Access tries to save the record, I can't find any way to
> intercept the error. Surprisingly the form_error event does not fire.
>
> The error can be handled using the form before_update, and trapping for
> errors at the save command but it's not very elegant. Any suggestions?


Home | Search | Terms | Imprint
Newsgroups Reader