Help with Cancel SendObject error

scottb
4StarLounger
Posts: 402
Joined: 14 Apr 2010, 15:59

Help with Cancel SendObject error

Post by scottb »

Hi everyone,
I’m getting a Run-time error ‘2501’” The SendObject action was cancelled. Message when I cancel sending an email generated with the following code (cancel occurs within Outlook). When I select Debug the DoCmd.SendObject line is highlighted:

Code: Select all

Private Sub lblNewEmail_Click()
   Dim sExistingReportName As String
   Dim sAttachmentName As String

'Input variables
   sExistingReportName = "RptIndividualDonarRcpt2" 
   sAttachmentName = "Gram Seva Foundation Donation Receipt"    

   DoCmd.OpenReport sExistingReportName, acViewPreview, , , acHidden
   Reports(sExistingReportName).Caption = sAttachmentName 
   DoCmd.SendObject acSendReport, sExistingReportName, "PDFFormat(*.pdf)", [E Mail], , , "Gram Seva Foundation Donation Receipt For " & [First 
   Name] & " " & [Last Name] & "", "Receipt for your donation attached.  Thank you for your generous support." & vbCrLf & "Gram Seva Foundation", 
   True, ""
   
   DoCmd.Close acReport, sExistingReportName
   DoCmd.Close acForm, "frmqryDonationDepDatePopup"

cmdlblNewEmail_Click_Exit:
   Exit Sub

cmdlblNewEmail_Click_Err:
      MsgBox "You have cancelled the Email Receipt Action.  Click OK to get back to work.", vbInformation, "Gram Seva Foundation"
      Resume cmdlblNewEmail_Click_Exit

End Sub
I’m not certain where the problem is because I want Access to cancel the SendObject action.
Any help would be appreciated.
Happy New Year to all!
-Scott

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Help with Cancel SendObject error

Post by HansV »

You forgot to include an On Error GoTo line.
Just above DoCmd.SendObject, insert

Code: Select all

   On Error GoTo cmdlblNewEmail_Click_Err
Best wishes,
Hans

scottb
4StarLounger
Posts: 402
Joined: 14 Apr 2010, 15:59

Re: Help with Cancel SendObject error

Post by scottb »

Thank you Hans. Been looking at this so long I went snow blind. Much appreciated.