Microsoft KB Archive/148358

= ACC: Line Numbers Not Automatically Returned by Erl Variable =

Article ID: 148358

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition

-



This article was previously published under Q148358



SYMPTOMS
Advanced: Requires expert coding, interoperability, and multiuser skills.

When a run-time error occurs in a Visual Basic for Applications user- defined function with error handling in effect, the Erl function returns 0 unless a line number is specified in the user-defined function.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to the "Building Applications with Microsoft Access for Windows 95" manual.

NOTE: Visual Basic for Applications (used in Microsoft Access version 7.0) is called Access Basic in earlier versions.



RESOLUTION
You can return a line number in the Erl function by specifying a line number on or above the line that causes the error. The Erl function will return the line number currently in effect. You must specify a numeric line number, not an alphanumeric line label. The Erl function will only return a line number. For an example of how this works, see the "Steps to Work Around Behavior" section later in this article.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Open any database. Open a new module.  Type the following code: Sub ErrorTest Dim x as Integer               ' Declare variable. On Error Goto ErrorTest_Error x = 5 / 0                      ' Divide by zero error. Exit Sub

ErrorTest_Error: Debug.Print "Error occurred in line #" & Erl Resume Next End Sub  Open the Debug window. Type the following line in the Debug window (or Immediate window in 1.x and 2.0), and then press ENTER:

ErrorTest

Note that you receive the following error:

Error occurred in line #0

</ol>

Steps to Work Around Behavior
<ol> Open the module containing ErrorTest.</li>  Modify ErrorTest as follows: Sub ErrorTest Dim x as Integer               ' Declare variable. 10:                                ' NEW LINE!!! On Error Goto ErrorTest_Error 11:                                ' NEW LINE!!! x = 5 / 0                      ' Divide by zero error 12:                                ' NEW LINE!!! Exit Sub

ErrorTest_Error: Debug.Print "Error occurred in line #" & Erl Resume Next End Sub </li> Open the Debug window.</li> Type the following line into the Debug window, and then press ENTER:

ErrorTest

Note that now you receive the following error:

Error occurred in line #11

</li></ol>

NOTE: In the example above, if the numeric line label 11 did not exist, the Erl function would have returned the number 10 as it is the first preceding numeric label.

<div class="references_section">