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???