Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    RyanP is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    60

    DoCmd SendObject The SendObject action was cancelled. You can't exit Microsoft Access now.

    DoCmd.SendObject acSendReport, stDocName, acFormatPDF, "", , , "Emailing" & " " & strFileName


    'Close the Report
    DoCmd.Close acReport, stDocName

    Exit_cmdX_Single_Click:
    Exit Sub

    Cancel_cmdX_Single_Click:
    Exit Sub


    Cancel = True

    Err_cmdX_Single_Click:
    DoCmd.Close acReport, stDocName

    Exit Sub
    Cancel = True
    DoCmd.CancelEvent
    MsgBox Err.Description
    Select Case Err.Number
    Case 2501

    This triggers but I still get the "The SendObject action was cancelled" message and subsequent application FAIL

    End Select
    Resume Exit_cmdX_Click
    End Sub


    Scenario:
    1) User closes the email without sending.
    2) They get the "The SendObject action was cancelled" message
    3) Then the Access application is locked and cannot be closed "You can't exit Microsoft Access now. If you're running a Visual Basic module that is using OLD or DDE, you may need to interrupt the module.
    4) User is forced to shut down MSACCESS.exe via Task Manager


    The cancel event was added as an attempt to stop this from happening all to no avail. Tried various methods; turning off the error description, exiting the sub etc... None trigger in the ACCDE.

    In the ACCDE, if they use the X button to close the message without sending the email, the "The SendObject action was cancelled" message appears and insert FAIL function

    Windows 7 32 & 64 bit : Office Pro Plus 2010 32 bit (mix of 14.0.6029 & 14.0.7015) (tested on multiple PCs, all behaving the same way): ACCDE database

    This was marked as solved on the "sendobject on cancel error" however I'm not entirely sure why or how...

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    I dont see the need for ALL this code.
    Remove everything except:

    Code:
    DoCmd.SendObject acSendReport, stDocName, acFormatPDF, "", , , "Emailing" & " " & strFileName
    end Sub
    And you get an error put back the error handling part:

    Code:
    Exit Sub
    
    errSend:
    MsgBox Err.Description

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Are you trying to trap an error 2501?

    You need to put your error trapping prior to your first Exit Sub line. Do you have an on error GoTo Err_cmdX_Single_Click prioir to your DoCmd.SendObject?

  4. #4
    RyanP is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    60
    Quote Originally Posted by ItsMe View Post
    Are you trying to trap an error 2501?

    You need to put your error trapping prior to your first Exit Sub line. Do you have an on error GoTo Err_cmdX_Single_Click prioir to your DoCmd.SendObject?

    Yes, I have that... just didn't include it in the code example (sorry)

    It goes to the error properly, but does not proceed to the EXIT... Access gets locked and cannot be closed "You can't exit Microsoft Access now. If you're running a Visual Basic module that is using OLD or DDE, you may need to interrupt the module.

  5. #5
    RyanP is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    60
    Quote Originally Posted by ranman256 View Post
    I dont see the need for ALL this code.
    Remove everything except:

    Code:
    DoCmd.SendObject acSendReport, stDocName, acFormatPDF, "", , , "Emailing" & " " & strFileName
    end Sub
    And you get an error put back the error handling part:

    Code:
    Exit Sub
    
    errSend:
    MsgBox Err.Description
    If I have no On Error GoTo / Error code, then ACCDE just outright fails. If I have the On Error GoTo / Error code (resume Exit) the ACCDE goes to the error properly, but does not proceed to the EXIT... Access gets locked and cannot be closed "You can't exit Microsoft Access now. If you're running a Visual Basic module that is using OLD or DDE, you may need to interrupt the module.

    As for the cancels etc... I didn't have them there initially. They were an in vain attempt to avoid the "The SendObject action was cancelled" / "You can't exit Microsoft Access now. If you're running a Visual Basic module that is using OLD or DDE, you may need to interrupt the module." scenario...

  6. #6
    RyanP is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    60
    Doesn't look like I noted it on my initial post. If I'm in a ACCDB, this does not occur. Only an issue in the ACCDE...

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by RyanP View Post
    Doesn't look like I noted it on my initial post. If I'm in a ACCDB, this does not occur. Only an issue in the ACCDE...
    I should have a chance to check this out later. I will try and create an error trap to manage it. It might be as easy as adding a Do Events.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I was able to get this to work in an accdr. No error or message box or anything.

    Code:
    Private Sub Command0_Click()
    
    On Error GoTo MyError
    
    DoCmd.SendObject acSendReport, "ReportName", acFormatPDF, "Me@Domain.com"
    
    Resume_MyError:
    Exit Sub
    
    MyError:
    Select Case Err.Number
    Case 2501
    GoTo Resume_MyError
    Case Else
    MsgBox "There was an error." & vbCrLf & Err.Number & vbCrLf & Err.Description
    GoTo Resume_MyError
    End Select
    
    End Sub

  9. #9
    RyanP is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    60
    In the ACCDE with the Nav Pane displayed, I do not get the error using your code.
    I didn't realize it had any bearing on the subject so I didn't mention it before; but it appears that the problem is only present in the ACCDE when I set the Current Database - Display Navigation Pane setting to OFF.
    In that scenario, the error appears with your code as well.

    Doesn't matter if the NAV Pane is turned off via the Current Database Option or programmatically via VBA.

    Aside from a workaround, why would the NAV PANE being hidden have such an effect?

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by RyanP View Post
    ...Display Navigation Pane setting to OFF.
    In that scenario, the error appears with your code as well. ...
    I just tested the code I posted with the Nav Pane hidden via the options. I went through the extra step of making an accde vs. changing the extension to accdr. I did not have any issues launching a new Email, canceling, and then launching another email. I tried the same thing with the Nave Pane visible, no issues.

    Not sure why you are still having problems. I have used similar code in production DB's as executables and never had a problem. Perhaps you can do like I did and make a separate, blank, DB. Drag a table into it and run the Wizard to create a Report. Then test the code in the new DB.

  11. #11
    RyanP is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    60
    new blank DB with 1 form to call, one report to export and 1 table as the recordsource... accde / accdr dont' get the "The SendObject action was cancelled" / "You can't exit Microsoft Access now. If you're running a Visual Basic module that is using OLD or DDE, you may need to interrupt the module." scenario...


    Made a new DB. imported all objects, set the appropriate VB references. make the accde and accdr. "The SendObject action was cancelled" conflict in the Library references?

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    using OLD or DDE
    I am not sure what OLD is. I don't suppose your are using DDE if you created a new DB. Perhaps there is a default setting in options for DDE that is global. I did not create any special references in my sample DB. My DB file is in a trusted Folder. That is the only thing I can think that might be different.

    I do not get the same error message you get if I comment out the Error trapping.

    .
    Click image for larger version. 

Name:	emailError.jpg 
Views:	28 
Size:	64.5 KB 
ID:	21089

  13. #13
    RyanP is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    60
    sry...OLE. my bad

    noticed someone else had this problem at some point....Error Handling if DoCmd.SendObject is cancelled

    am fine with giving up on DoCmd.SendObject based on everything i've read on it.
    But alas, still a newb and not 100% how to convert the report to pdf and attach it to the email without using DoCmd.SendObject OR not having to save the PDF to a file first.
    Not a bid deal though. I guess I can just use the OutputTo acReport to a predefined location and use it as the attachment

  14. #14
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I will work up some examples after I get some sleep.

  15. #15
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862

    Email Example with Automation of Outlook

    This code seems to work good as a standalone. I did not have any issues with warnings, security or otherwise.

    Code:
    'before exporting your report you will want to make
    'sure there is not a file in the folder with the same name
    'and that the folder actually exists
    
    'create a report in a temp folder
    DoCmd.OutputTo acOutputReport, "ReportName", acFormatPDF, "C:\Test\PDF_Files\Test.pdf"
    
    'Reference Microsoft Outlook and
    'use early binding
    Dim objOutlook As New Outlook.Application
    Dim objNewEmail As MailItem
    Dim objAttachReport As Attachments
    
    'Instantiate your objects
    Set objNewEmail = objOutlook.CreateItem(olMailItem)
    Set objAttachReport = objNewEmail.Attachments
    
    'Add your file to the Attachments Collection
    objAttachReport.Add "C:\Test\PDF_Files\Test.pdf", olByValue
    
        With objNewEmail
            .BodyFormat = olFormatRichText
            .To = "MyEmail@Domain.com"
            .Subject = "Test Message"
            .HTMLBody = "This is the body of the message"
            'Save the email to ensure the attachment is a
            'copy of the original file (olByValue)
            .Save
            .Send
        End With
    
    'tidy up
    Set objAttachReport = Nothing
    Set objNewEmail = Nothing
    Set objOutlook = Nothing
    
    MsgBox "Complete"

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. ACCDE doesn't run the Sendobject action
    By Tom Hovens in forum Programming
    Replies: 0
    Last Post: 03-10-2015, 07:55 AM
  2. docmd.sendobject problems... oy
    By redbull in forum Programming
    Replies: 3
    Last Post: 08-08-2013, 06:30 AM
  3. Table NOT TO update if SendObject cancelled
    By Hello World in forum Forms
    Replies: 1
    Last Post: 10-14-2011, 09:41 AM
  4. Email sent via DoCmd.SendObject
    By silverback in forum Programming
    Replies: 0
    Last Post: 10-29-2009, 06:26 AM
  5. DoCmd.SendObject Help
    By bgreer5050 in forum Programming
    Replies: 0
    Last Post: 01-12-2007, 06:27 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums