How to trap error number and error discription

tony007

Registered User.
Local time
Today, 12:52
Joined
Jun 30, 2005
Messages
53
Hi guys. i want to trap error number and error discription when error happens in access 2000 forms(on form error event). I want grab those values and show the user a customed message box and over ride the access error. I be happy if some one show me how to do this.Thanks
 
Last edited:
Code:
Public Function FunctionName()
On Error Goto Err_Handler
<insert your code here>
Ext_Procedure:
    Exit Function
Err_Handler:
    MsgBox Err.Number & " " & Err.Description
    Resume Ext_Procedure
End Function
 
modest said:
Code:
Public Function FunctionName()
On Error Goto Err_Handler
<insert your code here>
Ext_Procedure:
    Exit Function
Err_Handler:
    MsgBox Err.Number & " " & Err.Description
    Resume Ext_Procedure
End Function


Thanks for u reply. does this code over rides the access errors? i want some how over ride that error . Furtheremore, if i want to use this on form error is there a way to add if statement to this script so for each error it show diffrent massage.Thanks
 
I have never experienced a Form/Access Error, if I believe that's what you're looking for. That would be considered an application error which Windows should take care of when it asks you to send to microsoft.

Instead, I woud say that what I showed you is a demonstration of how to trap errors for function. These functions could be form events, or other functions you have written.
 
tony007 said:
Thanks for u reply. does this code over rides the access errors? i want some how over ride that error . Furtheremore, if i want to use this on form error is there a way to add if statement to this script so for each error it show diffrent massage.Thanks
Once you know what the runtime error number is then you can trap for it and give the user a custom message just for that error number. Like this using modest's code...

Code:
Public Function FunctionName()
On Error Goto Err_Handler

<insert your code here>

Ext_Procedure:
    Exit Function
Err_Handler:
    if err.number = 2501 then 'The RunCommand action was canceled
         msgbox "you canceled the previous operation."
         exit function
    else
         MsgBox Err.Number & " " & Err.Description
         Resume Ext_Procedure
    end if
 
End Function
 

Users who are viewing this thread

Back
Top Bottom