knowing error line and module name

  • Thread starter Thread starter x taol
  • Start date Start date
X

x taol

i wanna know error line and module name when outbreak of error in any
module.

Sub test()
On Error GoTo erohandle:
~~~~~
~~~~~
Exit Sub
erohandle:
MsgBox "the current module name is " & xxxx & vbCrLf & "the line number
is " & yyyyy
End Sub
 
look at help on erl - however you have to have explicit line numbers written
into your code (the old Basic way).

Other than that, you will have to code it yourself.
 
There is no automated way, but you could the module name in a constant and
scatter line numbers periodically through the procedure, and then use the
Erl function to get the last line
number encountered before the error was raised. E..g,

Here is an example

Sub TestErrorLineNumber()
Const sModule As String = "Module1"

On Error GoTo ErrHandler:
10:
' some code
20:
' more code
Err.Raise 1
'etc.
Exit Sub
ErrHandler:
MsgBox "Error: " & Err.Number & " " & Err.Description & vbNewLine & _
"in module: " & sModule & " in project: " & Err.Source & vbNewLine &
_
"around the following line: " & Erl
End Sub

You could also add the procedure name.


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
The MZTools add in is quite useful for this.

There is a routine that add's/removes line numbers to your code, and a
routine that will add an error handler to a module with the name of the
module included automatically.

Robin Hammond
www.enhanceddatasystems.com
 
Back
Top