Reputation: 377
I have the following VBA Access code which is working fine except for the fact that when the user decided to close the Outlook window and decided not to send the email the Access interface freezes:
Dim strSubject As String
strSubject = "Receipt number: " & [Reports]![RCPT_MAIN_EMAIL].[RECEIPT]
Dim strBody As String
strBody = "Dear Sir/Madam," & vbCrLf
strBody = strBody & "Attached Receipt number " & [Reports]![RCPT_MAIN_EMAIL].[RECEIPT] & " for your payment." & vbCrLf
DoCmd.SendObject acReport, "RCPT_MAIN_EMAIL", acFormatPDF, [Reports]![RCPT_MAIN_EMAIL].[Email], "[email protected]", "", strSubject, strBody, True, ""
'DoCmd.Close acReport, "RCPT_MAIN_EMAIL", acSaveNo
send_res_email_Exit:
DoCmd.Close acReport, "RCPT_MAIN_EMAIL", acSaveNo
Exit Function
send_res_email_Err:
MsgBox Error$
Resume send_res_email_Exit
End Function
This basically opens a hidden form, reads the EMAIL value and sends the email via Outlook. But if the user decide to close the outlook message window it gives a message saying that The SendObject was cancelled and freezes.
Upvotes: 1
Views: 469
Reputation: 27634
In your scenario, I would simply add a
On Error Resume Next
before the DoCmd.SendObject
line.
If you need to take action when the message is not sent, do
On Error Resume Next
DoCmd.SendObject acReport ...
If Err.Number <> 0 Then
' User has canceled
End If
Upvotes: 1