0

I would like to be able to have an error message that tells me which procedure my error is in.

Here's an example of a basic error handler I may use:

err_Handler:
   Dim msg As String
    If Err.Number <> 0 Then
        msg = "Error #" & Str(Err.Number) & " error Line: " & Erl & Chr(13) & _
               Err.Description
        MsgBox msg, , "Error", Err.HelpFile, Err.HelpContext
    End If
    Exit Sub

I would like my message box to return something on the lines of "Error in Report_btn_click". to achieve this I need to be able to get my procedure name as a string so that I can put "error in " & strProcName.

However, I cant figure out how to do this or where to even start?!

Is it even possible?

Thanks!

LiamH
  • 1,492
  • 3
  • 20
  • 34
  • I normally use a public string and do something like this private sub xyz() : strprocname="xyz" – Nathan_Sav Mar 11 '16 at 09:13
  • 1
    I use MZ Tools (http://www.mztools.com/) - you can create a template to add error handling to each procedure which can include the procedure & module name. – Darren Bartrup-Cook Mar 11 '16 at 09:23
  • Take a look at http://stackoverflow.com/questions/3792134/get-name-of-current-vba-function this might be what you are looking for. – gizlmo Mar 11 '16 at 10:57

0 Answers0