Send Notification via Outlook E-mail when an Error Occurs in Your Application

Category:
Office/VBA
Type:
Snippets
Difficulty:
Intermediate
Author:
Stanley Campbell

Version Compatibility:

More information:
This Routine sends the specified recipient an e-mail via Outlook when an error occurs in a procedure. Outlook must be installed on the machine for the procedure to work

Here is an example of how to use the procedure:

Private Sub Form_Load()

On Error GoTo errHandler
Dim i As Integer
i = 1 / 0
Exit Sub

errHandler:
If err.Number > 0 Then
ErrorNotify err, "me@mydomain.com", "Form.Load"
End If

End Sub

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: