Results 1 to 13 of 13
  1. #1
    tinyb is offline Novice
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Posts
    5

    Outputto PDF cancelled

    I have the following code behind a button that should email a report in PDF format.................... it works fine in Windows Vista with Outlook 2007. When I transferred the database to a Windows 8 machine it gives the error "outputto action was cancelled" with no error number............... and does nothing.

    I have used the part of the code, the section that creates the file, without the Email Section on another button to create a PDF in a folder and that works fine so my suspicions are that the code for the Outlook is not correct for Windows 8.

    The code is as follows ....................



    Dim Filename As String
    Dim FilePath As String
    Dim oOutlook As Outlook.Application
    Dim oEmailItem As MailItem


    Filename = Me.[Customer Name] & "_InvoiceNo " & Me.InvoiceNo
    FilePath = "C:\Invoices\" & Filename & ".pdf"


    'create the file in the folder
    DoCmd.OutputTo acOutputReport, "MailDelInvoice", acFormatPDF, FilePath

    'test if outlook is open and if not opens it

    If oOutlook Is Nothing Then
    Set oOutlook = New Outlook.Application
    End If

    Set oEmailItem = Outlook.CreateItem(olMailItem)
    With oEmailItem
    .To = Me.Email
    .Subject = "Invoice Number: " & Me.InvoiceNo
    .Attachments.Add FilePath
    .Display
    End With

    Set oEmailItem = Nothing
    Set oOutlook = Nothing
    'delete the file in the folder
    Kill FilePath

    When I click the button to activate this code you can see it working to create the file ............... but then It gives me the "outputto action was cancelled" ...........

    As I said I used part of the code to create the file in a folder without mailing it............... and it works

    Dim Filename As String
    Dim FilePath As String

    Filename = Me.[Customer Name] & "_InvoiceNo " & Me.InvoiceNo
    FilePath = "C:\Invoices\" & Filename & ".pdf"

    'create the file in the folder
    DoCmd.OutputTo acOutputReport, "MailDelInvoice", acFormatPDF, FilePath

    This works perfect and creates the file as indicated.

    Is there a problem with the outlook in this code. Should I have made my variables for Outlook - objOutlook etc..........

    Any help is appreciated.

    MB

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Not sure I have an answer but I had seeing a question go unanswered. So the file is never created (take out the Kill to be sure)? I had a different error moving to Win 8 but my file was created and it was the Outlook code that barfed. I can't imagine why the file wouldn't be created if everything else is the same. You tried both on the same machine? My first thought was that the user didn't have write permission to that folder.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    If the user does not send the email, Access will produce a Run Time error. You need to trap for the error. Use the error number provided in the message to handle the specific error within your code.

  4. #4
    tinyb is offline Novice
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Posts
    5

    Error on Email

    Quote Originally Posted by ItsMe View Post
    If the user does not send the email, Access will produce a Run Time error. You need to trap for the error. Use the error number provided in the message to handle the specific error within your code.
    The Only error I get is the dialog telling me the Outputto Action was cancelled. I am not sure how to trap it and use !!!

    If I try the code again without the Kill command to see how that works.

    thanks again for the help.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Quote Originally Posted by ItsMe View Post
    If the user does not send the email, Access will produce a Run Time error. You need to trap for the error. Use the error number provided in the message to handle the specific error within your code.
    That's true with SendObject; does it also happen with automation? My gut is no, but I always have error trapping anyway.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by pbaldy View Post
    That's true with SendObject; does it also happen with automation? My gut is no, but I always have error trapping anyway.
    No, it is not true with automation. After I posted I started to think about it and put it to the test.

    I could not reproduce the error described in the OP. I included the Kill line and it did not have a problem. So it could be a permission thing where the user can create stuff in the folder but cannot delete.

  7. #7
    tinyb is offline Novice
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Posts
    5

    Error Code

    Quote Originally Posted by ItsMe View Post
    No, it is not true with automation. After I posted I started to think about it and put it to the test.

    I could not reproduce the error described in the OP. I included the Kill line and it did not have a problem. So it could be a permission thing where the user can create stuff in the folder but cannot delete.
    Without the outlook part of the code ........ on Windows 8 I can create the file.

    When I add the part of the code to open outlook and attach the file created it breaks down.............. I think when it hits the part to open Outlook it falls down......... could it be that the code is unsure where outlook is located on an x64 operating system machine...................?????

    Again thanks for all the replies.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    You haven't clarified, is the file created, despite the message? It makes no sense that adding the Outlook code would affect the creation of the file. In my case, I got an error about "method TO failed", and it turned out I had to set the To indirectly. It didn't like

    MyMail.To = rs!MaxOfEmail

    but this worked:

    strEmail = rs!MaxOfEmail
    MyMail.To = strEmail
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I do not understand why you would get that error. As mentioned, other errors might be expected before getting the error you are describing.

    Are you able to compile your code without getting a compilation error?

  10. #10
    tinyb is offline Novice
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Posts
    5
    When I activate the button I can see the printer trying to create the file and it stops with the warning "OutPutTo action cancelled" and no file is created. If I comment out -


    If oOutlook Is Nothing Then
    Set oOutlook = New Outlook.Application
    End If

    Set oEmailItem = Outlook.CreateItem(olMailItem)
    With oEmailItem
    .To = Me.Email
    .Subject = "Invoice Number: " & Me.InvoiceNo
    .Attachments.Add FilePath
    .Display
    End With

    Set oEmailItem = Nothing
    Set oOutlook = Nothing
    'delete the file in the folder
    Kill FilePath

    The file is created.......... so that leads me to think the code for opening the outlook app is not the same for Vista and Win 8............ In vista the file is created and the email application opens but on Win 8 not a stir..............

    Commenting out the KillPath doesn't improve matters......

    I hope this is more helpful.........

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    You're testing with the same record displayed on the form? So that the same file is trying to be created? In other words, the file name and path variables resolve to the same thing? I can't think of any way the Outlook code could affect the file creation. I have similar code running on Win 8 machines (and has been running since A2000), and like I said the only change I made was to the "To". I don't suppose you can attach the db here that fails? I've got a Win 8 VM I can test it on.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    tinyb is offline Novice
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Posts
    5

    Em,ail Report

    Quote Originally Posted by pbaldy View Post
    You're testing with the same record displayed on the form? So that the same file is trying to be created? In other words, the file name and path variables resolve to the same thing? I can't think of any way the Outlook code could affect the file creation. I have similar code running on Win 8 machines (and has been running since A2000), and like I said the only change I made was to the "To". I don't suppose you can attach the db here that fails? I've got a Win 8 VM I can test it on.
    Thanks for all the help. I decided to re-write the same code again and what do you know it worked. Sorry for taxing all your minds when the solution turned out to be as simple as that. I still haven't a clue how that sorted the problem but its working and I am a happy bunny........... Thanks folks you were all star performers with your efforts.

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Glad you got it running and welcome to the site!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 09-12-2014, 03:15 AM
  2. Error When Event is Cancelled
    By tylerg11 in forum Forms
    Replies: 1
    Last Post: 02-07-2012, 09:48 AM
  3. OpenReport cancelled
    By wharting in forum Reports
    Replies: 15
    Last Post: 11-11-2011, 02:34 PM
  4. The OpenReport action was cancelled
    By Paul H in forum Reports
    Replies: 5
    Last Post: 11-11-2011, 02:27 PM
  5. Table NOT TO update if SendObject cancelled
    By Hello World in forum Forms
    Replies: 1
    Last Post: 10-14-2011, 09:41 AM

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