D Willett
SilverLounger
Posts: 1728 Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England
Post
by D Willett » 07 Aug 2014, 16:20
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.
HansV
Administrator
Posts: 78391 Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands
Post
by HansV » 07 Aug 2014, 16:26
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
Post
by D Willett » 07 Aug 2014, 16:42
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.
HansV
Administrator
Posts: 78391 Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands
Post
by HansV » 07 Aug 2014, 16:49
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
Post
by D Willett » 07 Aug 2014, 17:06
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.
HansV
Administrator
Posts: 78391 Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands
Post
by HansV » 07 Aug 2014, 17:13
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
Post
by D Willett » 07 Aug 2014, 18:00
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.
HansV
Administrator
Posts: 78391 Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands
Post
by HansV » 07 Aug 2014, 18:01
Great!
Best wishes,
Hans