Error in VBA code (To send email)

Gerrit.B

Board Regular
Joined
Aug 10, 2004
Messages
237
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I use code below to send email messages.
When canceling sending mail all seems to work.
But if I send mail it doesn't update status, but is goes directly to MsgBox "Can't Create Report"

What did I wrong?

Code:
On Error GoTo Err_DblClick_Click

If not IsNull(Me.EmailAddress) Then


DoCmd.SendObject acReport, [Report], "PDFFormat(*.pdf)", [EmailAddress], "", "", "Subject", "", True, ""


MsgBox "Message Send"
Me.Status = Me.Status + 1
Else
DoCmd.CancelEvent
End If
Exit_DblClick_Click:
Exit Sub


Err_DblClick_Click:
If Err.Number = 2501 Then
MsgBox "Send Message is Cancelled"
Resume Exit_DblClick_Click
Else
MsgBox "Can't Create Report"
Exit_DblClick_Click
End If
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try disabling the error handling (comment out the On Error statement) and step thru the code line by line to see if there may be an unexpected error trapping things.
 
Upvote 0

Forum statistics

Threads
1,221,827
Messages
6,162,202
Members
451,752
Latest member
freddocp

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top