Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handling

Status
Not open for further replies.

sim2

MIS
Jan 15, 2001
1
CA
How can i have the current function name to include in the error message?

erreur_code:
Dim errmsg As String
Dim errmsg1 As String
Dim errmsg2 As String
Dim errmsg3 As String

If fLocaleInfo(LOCALE_SENGLANGUAGE) = "French" Then
errmsg = "Veuillez noter le message suivant et contacez l'infomatique!"
errmsg1 = Chr(13) & "Module : " & err.Source
errmsg2 = Chr(13) & "No Erreur:" & err.Number
errmsg3 = Chr(13) & "Message d'erreur :"

Else
errmsg = "Please note the following message and contact the help desk!"
errmsg1 = Chr(13) & "Module : " & err.Source
errmsg2 = Chr(13) & "No Error:" & err.Number
errmsg3 = Chr(13) & "Error message :"
End If

MsgBox errmsg & errmsg1 & errmsg2 & errmsg3 & err.Description, vbCritical, "Attention"
Resume fin


Thank you!
 
Access doesn't capture the procedure name when an error occurs. You have to capture it yourself.

One technique is to Dim a global variable strCurrProcName As String in a standard module, and insert the following code at the start of every procedure:
Code:
    Dim strCallingProcName As String
    strCallingProcName = strCurrProcName
    strCurrProcName = "(name of this procedure)"
Then insert the following code at every point where you exit the procedure:
Code:
    strCurrProcName = strCallingProcName
Your error handlers can then get the procedure name where an error occurred from strCurrProcName. Note that if you intend to Resume after the error, you should reset strCurrProcName to the name of the procedure containing the error handler before you Resume. Otherwise it will still have the lower-level (called) procedure's name in it, and if another error occurs it will get the wrong name. Also, this technique won't work right if you have any recursive procedure calls.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top