I have the following vba.
Private Sub Command25_Click()
Me.Dirty = False
DoCmd.OpenReport "nonconformity", acViewPreview, , "[nonconformid] =" & Me.NonConformID
DoCmd.SendObject acSendReport, , acFormatPDF, Forms![non conformity]![Contact]
DoCmd.Close acReport, "NonConformity", acSaveNo
This sends a report based on the current record displayed on the form to an email as a pdf attachment.
After sending the email, it closes the report and the user is back to the form .
This all works fine as long as the email is sent.
I'm trying to make this fullproof should a user decide not to send the email and close it instead, the following error displays when email is cancelled.
Error message Run-time error '2501': the SendObject action was cancelled
Can someone help me with the code to do the following: if email is cancelled, complete the vba (also closing the open report) & close the report displaying "Email message was Cancelled"
Else, "Message Sent Successfully"