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