X
XMan
How to catch database messages and replace them with my own? TIA.
Neil said:Just to add to this, forms have their own On Error events. The event passes
in 2 arguments, DataErr and Response. DataErr is the number of the error
that has occured. Response is how you wish to proceed after your code has
performed a task. What I do is declare constant error variables in the
General Declerations section (right @ the top of the form) and then use them
in my code later. This way you have a variable which gives an idea of the
error rather than just a number. The code for this would look as follows:
-------------------------------------------------------
Option Compare Database
Option Explicit
' Declare known errors
Const intErrConfirmCascadeDelete As Integer = 2861
Const intErrInputMaskIsInvalid As Integer = 1086
Const intErrDateEnteredIsInvalid As Integer = 5810
' Events and procedures will then start here....
-------------------------------------------------------
In the error event for the form your code would look something like this:
-------------------------------------------------------
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Debug.Print DataErr ' This will print the error number that has
occured into the immediate window so that you know the correct error number.
Delete this line once you know all the errors that you want to handle
yourself
' Check which error has occured
Select Case DataErr
Case intErrConfirmCascadeDelete
' Display a custom message box
MsgBox "This will delete all the records in all linked tables",
vbOKOnly
' Continue as normal
Response = acDataErrContinue
Case intErrInputMaskIsInvalid
' Do nothing - Let Access hadle this error
' This is pointless put just showing you that if you dont set the
response then Access handles the error as normal
Case intErrDateEnteredIsInvalid
' Ignore that this is an incorrect date and continue without a
warning being displayed (The record will not save though!)
Response = acDataErrContinue
End Select
End Sub
-------------------------------------------------------
The code above is just an example and can be modified to suit your needs.
Also, the error codes above are not correct.
HTH,
Neil.