ACC: Line Numbers Not Automatically Returned by Erl Variable

Last reviewed: August 28, 1997
Article 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

  1. Open any database.

  2. Open a new module.

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

  4. Open the Debug window.

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

  1. Open the module containing ErrorTest().

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

  3. Open the Debug window.

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

Keywords          : kbprg PgmErr
Version           : 1.0 1.1 2.0 7.0
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbprb
Solution Type     : kbcode


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.