PDA

View Full Version : Error Report



steve
12-19-2005, 06:47 AM
Hi All

I've written a procedure and I want to add some sort of error capture in it, I was hoping to have the line of code and procedure name in a error report that would be e-mailed to me. is there anyway of doing this??

Thanks
Steve

matthewspatrick
12-19-2005, 07:04 AM
Steve,

I do not think you can get the specific line. What you could do, though, is define a variable, and at various spots in the code change its value to indicate what 'section' of the code is executing. Then, use an error handler to create the email; the error handler can interrogate that variable to report the section to you.

steve
12-19-2005, 07:13 AM
Hi

Thanks Matthew, I shall give that a go and let you know!!

Cheers
Steve

Marcster
12-19-2005, 09:20 AM
Hi Steve,
There is an undocumeneted feature called Erl
Error Line Number
You use this to find out on what line the error occurred on.
On each statement line you need to key in a different number.
See the sample sub below:


Sub ErlError()
'
' Demostrates the undocumented Erl feature.
' On each statement line you need to manually key
' in a number, this will be used as the line number.
' When an error occures you use Erl to find out
' on what line the error occured on.
'

1 On Error GoTo ErlError_Error

2 Range("A0").Select 'Errors as there is no cell A0
'The following will not run due to the error above
3 Cells(1, 1) = "Some heading"
4 Cells(1, 2) = "Another heading"
5 Cells(1, 3) = "Yet another heading"

ErlError_Error:

6 MsgBox "An error has occurred." & vbCr & vbCr _
& "Error Number: " & vbTab & Err.Number & vbCr _
& "Error Description: " & vbTab & Err.Description & vbCr _
& "On Line: " & vbTab & vbTab & Erl, vbCritical Or vbSystemModal, "*** ERROR ***"

End Sub



The above sub will show a message box displaying the error's description
and number along with the line the error occured on.
Google for 'vba erl' to find out more.

The freeware 'MZ-Tools 3.0' from http://www.mztools.com/v3/mztools3.htm
is a great tool. One feature of this tool once set up
is it'll add your error handler and Erl lines for you.

Marcster.