Send Report PDFFormat as ........

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Send Report PDFFormat as ........

Post by D Willett »

Hi.
Can the following line of code be changed to send the report in PDFFormat from lstReports with a different output name?

Code: Select all

DoCmd.SendObject acReport, Forms![View Docs]!lstReports, "PDFFormat(*.pdf)", "", "", "", "Please find attached from M&M Signs and Graphics for Sales Order: " & Me.SalesOrderID & "-" & " Customer: " & Me.Customer.Column(1) & "-" & " Your Ref: " & Forms!frmSales![Order Number], "", True, """"
Cheers
Cheers ...

Dave.

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

Re: Send Report PDFFormat as ........

Post by HansV »

No, that is not possible. You'd have to use DoCmd.OutputTo to export the report to a PDF file on disk with a name specified by you, then use Automation to create an e-mail message in Outlook and attach the PDF file, and display the message.
Post back if you need more detailed info.
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Send Report PDFFormat as ........

Post by D Willett »

Code: Select all

    DoCmd.OutputTo acOutputReport, Forms![View Docs]!lstReports, acFormatPDF, "C:\" & lstReports & "-" & Me.SalesOrderID & "-" & Me.Customer.Column(1) & ".pdf"

    DoCmd.SendObject acReport, "C:\" & Me.SalesOrderID & "-" & Me.Customer.Column(1) & ".pdf", "Please find attached from M&M Signs and Graphics for Sales Order: " & Me.SalesOrderID & "-" & " Customer: " & Me.Customer.Column(1) & "-" & " Your Ref: " & Forms!frmSales![Order Number], "", True, """"
Close but quite got the Cigar !!!
Cheers ...

Dave.

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

Re: Send Report PDFFormat as ........

Post by HansV »

DoCmd.SendObject won't send a file from disk, only an object from within the database itself (or no object at all)...
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Send Report PDFFormat as ........

Post by D Willett »

Hi Hans
The following creates the pdf and then tells me it doesn't exist although it does in the C:\ drive..

Code: Select all

DoCmd.OutputTo acOutputReport, Forms![View Docs]!lstReports, acFormatPDF, "C:\" & lstReports & "-" & Me.SalesOrderID & "-" & Me.Customer.Column(1) & ".pdf"

Dim objOutlook As New Outlook.Application ' outlook object
Dim objMessage As MailItem, strAttach As String ' outlook mail message
strAttach = "C:\" & lstReports & "-" & Me.SalesOrderID & "-" & Me.Customer.Column(1) & ".pdf"
Set objMessage = objOutlook.CreateItem(olMailItem)
With objMessage
.To = ""
.Subject = "Please find attached from M&M Signs and Graphics for Sales Order: "
.Body = ""
.Attachments.Add strAttach
.Send
End With
Set objOutlook = Nothing
Set objMessage = Nothing
Cheers ...

Dave.

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

Re: Send Report PDFFormat as ........

Post by HansV »

Recent versions of Windows don't allow direct access to the root of C:\. Try using "C:\Temp\" instead of "C:\".
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Send Report PDFFormat as ........

Post by D Willett »

Got it............

Code: Select all

Dim myMail As String
Dim myID As String
    myMail = "C:\temp\" & lstReports & " Ref " & Me.SalesOrderID & " For " & Me.Customer.Column(1) & ".pdf"
    myID = Me.SalesOrderID & "-" & Me.Customer.Column(1)
    
    
    DoCmd.OutputTo acOutputReport, Forms![View Docs]!lstReports, acFormatPDF, "C:\temp\" & lstReports & " Ref " & Me.SalesOrderID & " For " & Me.Customer.Column(1) & ".pdf"
    
    
    Dim objOL As New Outlook.Application
    Dim objMail As MailItem
    Set objOL = New Outlook.Application
    Set objMail = objOL.CreateItem(olMailItem)
    msg = "Please find attached documents from M&M Signs and Graphics Ref: " & myID
     
         
    With objMail
        .To = ""
        .Subject = msg
        .Body = ""
        .Display
        .Attachments.Add myMail
        
    End With
     
    Set objMail = Nothing
    Set objOL = Nothing
Cheers ...

Dave.

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

Re: Send Report PDFFormat as ........

Post by HansV »

Great!
Best wishes,
Hans