By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

error handling - a couple of questions:

P: n/a
I am writing error handling procedures at the moment. Here are some
questions:

1. Can you write a procedure that picks up any error and deals with it no
matter where it happens in the database?

2. Does Access keep a list of errors in a "secret" table?

3. Is there a way to handle common errors (such as - "you need to choose
from the list" or "a related record is required in ....") with just one
procedure that applies to all forms???
---
Please immediately let us know (by phone or return email) if (a) this email
contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.687 / Virus Database: 448 - Release Date: 16/05/2004
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In answer to 1 and 3, put your error code in a public sub in a standard module
and call it everywhere you need it.

In answer to 2, look at error codes in the Help file.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"WindAndWaves" <ac****@ngaru.com> wrote in message
news:R0*******************@news.xtra.co.nz...
I am writing error handling procedures at the moment. Here are some
questions:

1. Can you write a procedure that picks up any error and deals with it no
matter where it happens in the database?

2. Does Access keep a list of errors in a "secret" table?

3. Is there a way to handle common errors (such as - "you need to choose
from the list" or "a related record is required in ....") with just one
procedure that applies to all forms???
---
Please immediately let us know (by phone or return email) if (a) this email
contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.687 / Virus Database: 448 - Release Date: 16/05/2004

Nov 12 '05 #2

P: n/a
1. Generic error handler
Every Sub and Function must have its own error handling, but the procedure
can call a generic error handler to do the work.

For an example of a generic handler that logs errors to a table, see:
http://allenbrowne.com/ser-23a.html
For a free tool that drops the error handler into a procedure with one mouse
click, see:
http://www.mztools.com

You need to call another procedure in the Error event of your forms to catch
those errors also. These DataErr values are not easy to come by, but some
common ones are:
3022 duplicate index violation
3024 data file missing (e.g. network down).
3021 related record required
3314 field is marked Required, and no value supplied.
2113 invalid data type
2. Listing of error messages
You can get the internal errors from the AccessError method, e.g.:
? AccessError(2001)

There is a list of the JET errors in a file that depends on your version of
Access.
For A2003 it is JetErr40.chm, typically in:
\Program Files\Common Files\Microsoft Shared\OFFICE11\1033\
Create a shortcut to the file for quick access.
3. Common Errors
As described in #1 above, this is a matter of using error handling in all
procedures, and hooking the Error event of the form. Use a Select Case
statement to respond to the various errors, e.g.:
Select Case Err.Number
Case 3314, 2101, 2115
strMsg = "Record cannot be saved at this time." & vbCrLf & _
"Complete the entry, or press <Esc> to undo."
Case 0, 2501
'just ignore these.
Case Else
strMsg = Err.Description
End Select
If Len(strMsg) > 0 Then
MsgBox strMsg
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"WindAndWaves" <ac****@ngaru.com> wrote in message
news:R0*******************@news.xtra.co.nz...
I am writing error handling procedures at the moment. Here are some
questions:

1. Can you write a procedure that picks up any error and deals with it no
matter where it happens in the database?

2. Does Access keep a list of errors in a "secret" table?

3. Is there a way to handle common errors (such as - "you need to choose
from the list" or "a related record is required in ....") with just one
procedure that applies to all forms???

Nov 12 '05 #3

P: n/a
Thanks Allen, those are great links.
---
Please immediately let us know (by phone or return email) if (a) this email
contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.687 / Virus Database: 448 - Release Date: 16/05/2004
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.