ACC: Line Numbers Not Automatically Returned by Erl Variable
ID: Q148358
|
The information in this article applies to:
-
Microsoft Access versions 1.0, 1.1, 2.0, 7.0
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.
MORE INFORMATION
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
Steps to Work Around Behavior
- Open the module containing ErrorTest().
- 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
- Open the Debug window.
- 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
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.
REFERENCES
For more information about Error handling, search for "Error handling," and
then "Error Trapping" using the Microsoft Access for Windows 95 Help Index.
For more information about the Erl() function, search for "Erl" and then
"Err, Erl Functions" using the Microsoft Access Help menu.
NOTE: There is no reference to the Erl() function in the Microsoft Access
version 7.0 Help.
Additional query words:
Keywords : kbprg PgmErr
Version : WINDOWS:1.0,1.1,2.0,7.0
Platform : WINDOWS
Issue type : kbprb