Find Error Line Number in VBA With Erl

In this post you are going to find out a way of handling errors in your code with the Erl function.

Erl displays the last label before the error

Another alternative error handling solution is using labels at each point in long procedure.

Here we get a random error:

Here is the code behind the form:

Option Compare Database

Private Sub Command0_Click()
End Sub

Private Sub GenerateError()

    On Error GoTo err_handler
        Dim strForm As String
        s = 2
        y = 4
        strForm = "frmNothing"
        DoCmd.OpenForm strForm, acFormDS

Exit Sub

    MsgBox "You have an error " & Err.Number & ": " & Err.Description & " (Error at label - " & Erl & ")"
    Exit Sub
End Sub

Since the form “frmNothing” doesn’t exist, we have an error at line 40.

Again: Erl displays the last label before the error which may be beneficial to you.

Let me know if you have any questions.


Offsite Related Information:

“Go Fund Me” Page

($5 suggested amount)

(…10% of your gift amount will go to charity)

Free! Subscribe To Our YouTube Channel!

Free MS Access VBA Programming Course

Facebooktwitterredditpinterestlinkedinmailby feather
Tags: , , ,