PDA

View Full Version : [SOLVED] Line Number in Error Handler



NewDaddy
01-19-2007, 05:19 PM
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:banghead:

Bob Phillips
01-19-2007, 05:27 PM
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

NewDaddy
01-19-2007, 05:32 PM
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

Bob Phillips
01-19-2007, 06:00 PM
You might also want to get hold of MZ-Tools (http://www.mztools.com/v3/mztools3.htm), a must have add-in for VBA developers that adds line numbers to code.

NewDaddy
01-22-2007, 06:18 AM
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

Bob Phillips
01-22-2007, 06:35 AM
Speak to your IT guys NewDaddy, they will be the only ones with admin rights.