Jason Lee Hayes
Active member
- Local time
- Today, 04:34
- Joined
- Jul 25, 2020
- Messages
- 221
Hi,
I am exporting a report as PDF and it works fine using the DoCmd.SendObject method...
Report emails fine however if i cancel the outlook message and do not send i get the attached error as expected..
Anticipating this i thought my code would identify the code 2501 and ignore it (Ignore in that when i click cancel the outlook message closes and i am returned to the form. At the moment the message closes and the form is presented but cannot click on anything and have to force a TSR shutdown of the MS application.
I'm sure its something simple - a bit like me simple lol
Thanks in advance...
I am exporting a report as PDF and it works fine using the DoCmd.SendObject method...
Report emails fine however if i cancel the outlook message and do not send i get the attached error as expected..
Anticipating this i thought my code would identify the code 2501 and ignore it (Ignore in that when i click cancel the outlook message closes and i am returned to the form. At the moment the message closes and the form is presented but cannot click on anything and have to force a TSR shutdown of the MS application.
I'm sure its something simple - a bit like me simple lol
Thanks in advance...
Code:
Private Sub cmdEmail_Click() 'Output selected report as PDF and email
On Error GoTo Error_Handler
DoCmd.SetWarnings False
DoCmd.SendObject acSendReport, Me.lstQueries, acFormatPDF, _
"toemailaddress@outlook.com; andemailaddress@outlook.com", _
, "bccemailaddress@outlook.com", "Subject Here", "Message Body Here", False
DoCmd.SetWarnings True
exitMe:
On Error GoTo 0
DoCmd.Hourglass False
Exit Sub
Error_Handler_Exit:
DoCmd.Hourglass False
On Error Resume Next
Exit Sub
Error_Handler:
If Err = 2501 Then
' Report was cancelled, we can ignore this error
Else
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: frmPrintReport/cmdemail_Click()" & vbCrLf & _
"Error Description: " & Err.Description, vbCritical, _
"An Error has Occurred!"
Resume Error_Handler_Exit
End If
End Sub