Cancelling SendObject

DocB1973

Registered User.
Local time
Today, 05:58
Joined
May 12, 2010
Messages
16
The following code works fine except when the email pops up to the user and the user closes the email without sending. I get the message "Run time error 2501; The sendobject action was cancelled.

DoCmd.OutputTo acOutputReport, "rptQuotePrintedNew", "PDFFormat(*.pdf)", "http://team.enps.com/sites/LSLogistics/Spare%20Parts%20Kits/Quotes/Liebert Services Kit-Parts Quote - " & Forms!frmQuoteView!QUOTE_ID & ".pdf", False, "", 0, acExportQualityPrint
DoCmd.SelectObject acReport, "rptQuotePrintedNew", False
DoCmd.SendObject acReport, "rptQuotePrintedNew", "PDFFormat(*.pdf)", Forms!frmQuoteView![E-MAIL], "", "jeff.bourn@emerson.com", "Liebert Services Kit-Parts Quote - " & Forms!frmQuoteView!QUOTE_ID, "Attached is a quote for parts or parts kit. Please review and send the purchase order when the quote is accepted.", True, ""
Forms!frmQuoteView!PRINTDT = Now()
Forms!frmQuoteView!STATUS_ID = 5
Forms!frmQuoteView!FILELINK = "http://team.enps.com/sites/LSLogistics/Spare%20Parts%20Kits/Quotes/Liebert%20Services%20Kit-Parts%20Quote%20-%20" & Forms!frmQuoteView!QUOTE_ID & ".pdf"
DoCmd.Close acReport, "rptQuotePrintedNew"

Any help would be appreciated.
 
For that you put an error handler on whatever called the procedure that was going to do the sendobject. Something like:
Code:
Private Sub MyButton_Click()
On Error GoTo MyButton_err

' your code here

MyButton_Exit:
   Exit Sub

MyButton_err:
If Err.Number <> 2501 Then
   MsgBox Err.Description, vbExclamation, "Error #: " & Err.Num
End If
Resume MyButton_Exit

End Sub

And that way it will not report the 2501 error.
 
Bob,

Thank you so much for your reply. I tried your solution but am still getting the cancel sendobject message (see attached) when I cancel the email rather than sending it. The program goes back to the form I intended but the entire application is frozen at that time and I have to use task manager to close it. Here is my revised code.

Function SendMailMacro()
On Error GoTo MyButton_err
DoCmd.SetWarnings False
DoCmd.OutputTo acOutputReport, "rptQuotePrintedNew", "PDFFormat(*.pdf)", "http://team.enps.com/sites/LSLogistics/Spare Parts Kits/Quotes/Liebert Services Kit-Parts Quote - " & Forms!frmQuoteView!QUOTE_ID & ".pdf", False, "", 0, acExportQualityPrint
DoCmd.SelectObject acReport, "rptQuotePrintedNew", False
DoCmd.SendObject acReport, "rptQuotePrintedNew", "PDFFormat(*.pdf)", Forms!frmQuoteView![E-MAIL], "", "jeff.bourn@emerson.com", "Liebert Services Kit-Parts Quote - " & Forms!frmQuoteView!QUOTE_ID, "Attached is a quote for parts or parts kit. Please review and send the purchase order when the quote is accepted.", True, ""
Forms!frmQuoteView!PRINTDT = Now()
Forms!frmQuoteView!STATUS_ID = 5
Forms!frmQuoteView!FILELINK = "http://team.enps.com/sites/LSLogistics/Spare Parts Kits/Quotes/Liebert Services Kit-Parts Quote - " & Forms!frmQuoteView!QUOTE_ID & ".pdf"
DoCmd.Close acReport, "rptQuotePrintedNew"
DoCmd.SetWarnings True

MyButton_Exit:
Exit Function
MyButton_err:
If Err.Number <> 2501 Then
MsgBox Err.description, vbExclamation, "Error #: " & Err.Num
End If
Resume MyButton_Exit

End Function
 

Attachments

Well, the reason it is still happening is that

1. You didn't put it in the right event. It doesn't go in the SendMailMacro code, it goes in the place where you CALL SendMailMacro (I'm guessing a click event of a button).

2. You should, when you put it in there, change all of the places where it says MyButton to whatever the name of your button is (if it is a button that is calling the SendMailMacro).
 
Bob - that makes sense. However, I'm calling this function directly from a RunCode command in a macro that is being used as a shortcut menu bar for a report. Would you have a recommendation on how to handle that? Thank you so much for the input.
 
Bob - that makes sense. However, I'm calling this function directly from a RunCode command in a macro that is being used as a shortcut menu bar for a report. Would you have a recommendation on how to handle that? Thank you so much for the input.

Create another function to call it and call that function from the macro.
Code:
Function CallSendObject() 

On Error GoTo CallSendObject_Err

   Call SendMailMacro

CallSendObject_Exit:
   Exit Function

CallSendObject_Err:
   If Err.Num <> 2501 Then
      MsgBox Err.Description, vbExclamation, "Error #: " & Err.Num
   End If
      Resume CallSendObject_Exit

End Function

And then in your RunCode macro run CallSendObject instead and see if that helps.
 
Bob - I think I have the module the way you want it (see below). However, I'm still getting the error messages (see attached in the order that they appear). I changed the error message to the error number referenced on the error message. I've also attached a screen shot of my macro. Again, many thanks for your help.

Option Compare Database
Function CallSendObject()
On Error GoTo CallSendObject_Err
Call SendMailMacro
CallSendObject_Exit:
Exit Function
CallSendObject_Err:
If Err.Num <> 2950 Then
MsgBox Err.description, vbExclamation, "Error #: " & Err.Num
End If
Resume CallSendObject_Exit
End Function

Function SendMailMacro()
DoCmd.OutputTo acOutputReport, "rptQuotePrintedNew", "PDFFormat(*.pdf)", "http://team.enps.com/sites/LSLogistics/Spare Parts Kits/Quotes/Liebert Services Kit-Parts Quote - " & Forms!frmQuoteView!QUOTE_ID & ".pdf", False, "", 0, acExportQualityPrint
DoCmd.SelectObject acReport, "rptQuotePrintedNew", False
DoCmd.SendObject acReport, "rptQuotePrintedNew", "PDFFormat(*.pdf)", Forms!frmQuoteView![E-MAIL], "", "jeff.bourn@emerson.com", "Liebert Services Kit-Parts Quote - " & Forms!frmQuoteView!QUOTE_ID, "Attached is a quote for parts or parts kit. Please review and send the purchase order when the quote is accepted.", True, ""
Forms!frmQuoteView!PRINTDT = Now()
Forms!frmQuoteView!STATUS_ID = 5
Forms!frmQuoteView!FILELINK = "http://team.enps.com/sites/LSLogistics/Spare Parts Kits/Quotes/Liebert Services Kit-Parts Quote - " & Forms!frmQuoteView!QUOTE_ID & ".pdf"
DoCmd.Close acReport, "rptQuotePrintedNew"

End Function
 

Attachments

Let me see a screenshot of the module you have this code in (including the object explorer area of the VBA window).
 
Bob,

Here you go. I am only average experienced with VB so please let me know if there is a better way to do this.

Thanks,
Jeff
 

Attachments

Bob,

Here you go. I am only average experienced with VB so please let me know if there is a better way to do this.

Thanks,
Jeff
I think we could solve this problem quickly if we can just convert your macros over to VBA and then all would work as it should. Are you game for trying?

Access can do it for you and then we can just work with the parts we need to do.
 
Bob - These macros are housed in another macro called mcrShortcutMenucommands. I use mcrShortcutMenucommands as a shortcut menu for a report. I can take each macro in mcrShortcutMenucommands and convert it to VB if that would help.
 
I think the problem is that your macro just can't handle errors. Which is what Access 2007 introduced - Error handling in macros. So, regardless of what we do, because you need to use the macro for your menu you are going to have this problem in all versions prior to 2007.
 
Bob - I am using Access 2007. Any suggestions on how to handle errors in the macro?
 
Bob - I am using Access 2007. Any suggestions on how to handle errors in the macro?

Ah, then we have an error handler for that. Let me dig up some info on how to use that in the macros (I don't use macros so I'm a bit rusty and only know that the error handler exists in 2007 macros).
 
Bob - we are getting real close. I no longer get error messages. As you can see by the attached screen shot of the macro I had to put the error handling in the macro that is giving us the problem. I tried to put it at the top of this macro but that did not work. The only problem I am having now is that if I cancel the email the first time it works great. However, if I cancel the email twice it freezes the application. Any thoughts?
 

Attachments

Users who are viewing this thread

Back
Top Bottom