knowing error line and module name

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
 
T

Tom Ogilvy

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.
 
B

Bob Phillips

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)
 
R

Robin Hammond

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top