0

i currently have a form with a textbox and a button. you can enter any number in the textbox and when you hit the button it will show the number on a message box, but if there is an error, a message will pop up and you can click the debug button to see which line gave an error. This will be for the code:

On Error GoTo 0:

But if i replace the 0 with "error:", it will take me to a new subroutine that will send me an email regarding the issue but it will not highlight the line which gave me an error when i hit the debug button.

Is there a way i can send myself an email AND when i hit the debug button it will highlight the error line?

Private Sub CommandButton1_Click()

'on error goto error:
On Error GoTo 0:
    Dim word As Double
    word = TextBox1.Text
    MsgBox word
    Exit Sub

error:
    Call error()
End Sub


Sub error()

        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String

        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)

        strbody = "error"

        With OutMail
            .To = "[email protected]"
            .CC = ""
            .BCC = ""
            .Subject = "error"
            .Body = strbody
            .Send
        End With

        Set OutMail = Nothing
        Set OutApp = Nothing

    Debug.Assert (Err.Number & Err.Description)
End Sub
0

1 Answer 1

2

The below pattern calls error() then breaks in the IDE on the line that caused the error:

Sub Foo()
On Error GoTo ERR_HANDLER

    Dim i As Long
    i = i / 0

Exit Sub

ERR_HANDLER:
     Call error()
     On Error GoTo 0
     Resume
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.