Consulting

Results 1 to 6 of 6

Thread: Line Number in Error Handler

  1. #1
    VBAX Regular
    Joined
    Oct 2006
    Location
    Wiltshire, UK
    Posts
    43
    Location

    Line Number in Error Handler

    Header_Style2_Error:
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Header_Style2 of Module RPTG_Headers"
    Hi All

    Is it possible to include the line number in the procedure where the error occurred in error handling code?

    Cheers
    Jay

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You can, but the line numbers are not there implicitly, so you have to add them. Then test Erl.

    As an example

    Public Sub Test()
    10 Dim a As Long
    20    On Error GoTo Header_Style2_Error
    30    a = "ABC"
    40    Exit Sub
    50 Header_Style2_Error:
    60 MsgBox Erl & "Error " & Err.Number & " (" & Err.Description & ") in procedure Header_Style2 of Module RPTG_Headers"
    End Sub

  3. #3
    VBAX Regular
    Joined
    Oct 2006
    Location
    Wiltshire, UK
    Posts
    43
    Location
    Quote Originally Posted by xld
    You can, but the line numbers are not there implicitly, so you have to add them. Then test Erl.

    As an example

    Public Sub Test()
    10 Dim a As Long
    20 On Error GoTo Header_Style2_Error
    30 a = "ABC"
    40 Exit Sub
    50 Header_Style2_Error:
    60 MsgBox Erl & "Error " & Err.Number & " (" & Err.Description & ") in procedure Header_Style2 of Module RPTG_Headers"
    End Sub
    Hi xld

    Thank you very much, got that in and working.

    Cheers
    Julian

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You might also want to get hold of MZ-Tools, a must have add-in for VBA developers that adds line numbers to code.

  5. #5
    VBAX Regular
    Joined
    Oct 2006
    Location
    Wiltshire, UK
    Posts
    43
    Location
    Hi xld

    Thanks, having problems loading up MS tools. Can do it at home no problems but not at work as it is a exe file and need admin rights to install.
    working on this problem!!

    Cheers
    Jay

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Speak to your IT guys NewDaddy, they will be the only ones with admin rights.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •