Retrieving the procedure name at run time

Posted on 2006-06-27
Last Modified: 2010-04-07
I am writing a global procedure that send an email to the sys admin when an erro occurs in the app. Besides the error info, I would like to include in the email message: the Form name  (, the procedure name (???) and the actual line of code that generated the error (or the line number???).

the procedure name :
     Is there a way to retrieve the proc name turning runtime, without having it hard-coded in the call statement?

     current syntax:
       Call ErrorNotify err, "", Me.Name & ".Form_Load"

     would like it to be something like:
       Call ErrorNotify err, "", Me.Name & "." & < proc name >

the line that caused the error:
      Is there a way to retrieve the line of code that caused the error?


Question by:jones_r
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16996616
in vb6, there is no automatic way to get that information. only from on you have the call stack information available from code.
LVL 13

Assisted Solution

Mark_FreeSoftware earned 200 total points
ID: 16997136
the name of the procedure is not possible (without hardcoding it)

the line is possible!

you have to assign numbers to lines,
and then to find the line, you ahve to use the (undocumented) function erl


private sub Form_load()
dim i as long
on error goto error_1
1  msgbox "Hello"
2 i = inputbox("what value?")
3 i = i + 5
4  i = 5/0
exit sub
msgbox "The error occured on line " & erl
end sub

this will find an error on line 4
if you enter a string, it will find an error on line 2

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Accepted Solution

gafoorgk earned 300 total points
ID: 16998614
well, it's true that you cannot retrieve the procedure name in normal way. but it can be done using "Microsoft Visual Basic 6.0 Extensibility" library. i don't recommend using that before u know a bit about extending vb functionality.

instead use the nice free add-in tool MZ-Tools v3.0 for VB6. goto for that

Expert Comment

by:Naveen Swamy
ID: 17000581
hope the above links helps you

Author Comment

ID: 17004024
Gafoorgk  - the add-in was able to auto assign the line numbers and has a function to auto add the proc name in the error statement.  Overall, a very cool tool.

Mark - the erl function is a great find!  Thanks!  (though I would have hated to have had to manually enter all the line numbers for this to have worked)

Was not sure what the etiquette is when both of your answers helped me to achieve the final solution -- I marked the more helpful one as the accepted answer and split the points 300 - 200 (???)

The error statement in the proc is auto populated by the mz tools add-in 'create error statement' function

230        If err.Number > 0 Then
240          Call err_emailHandler(err, "Form_Load")
               'Resume Next
250        End If
End Sub

This proc gathers the error, line number, and form name + proc name and sends it to the global email proc (which generates the email to the admin)

Private Sub err_emailHandler(err As ErrObject, ProcName As String)
10            ErrorNotify err, Erl, Me.Name & "." & ProcName
End Sub

Again -- thanks!!

LVL 13

Expert Comment

ID: 17004277
>>Was not sure what the etiquette is when both of your answers helped me to achieve the final solution -- I marked the more helpful one as the accepted answer and split the points 300 - 200 (???)

as far as i know, that's the function of the split option!

(i like to give points that way too)

>>The error statement in the proc is auto populated by the mz tools add-in 'create error statement' function
//extra (free) tip:
did you know that you can edit this error statement?
click in tools (in the menu)
then mz-tools then options

then click on the tab error handler

thanks for the points, and happy coding!

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month4 days, 1 hour left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question