Save Report to PDF in designated folder (1 Viewer)

lunchbox

New member
Local time
Today, 06:21
Joined
Sep 27, 2017
Messages
5
Hi Guys,

I'm after some guidance please as I’m sure I’m going a long and complicated way about things here.

Basically I have a report that’s generated from a query to select the current viewed record in a form.

What I want to do is click a button on the form and have the report print 3 times and save as a pdf in a specific folder with the name taken from the report.

I can get it print 3 times and export to a pdf with the name taken from the report I just can’t get it so save in a folder of my choosing (C:\exports).

The code I have so far is:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "Bedfords", acViewPreview
DoCmd.PrintOut , , , , 3
DoCmd.OutputTo acOutputReport, Bedfords, acFormatPDF, Me.Customer_Order_Number & ".pdf", True, "", 0

Could someone please point me in the right direction to add in the folder I want to export it to?

Thanks in Advance
 

Ranman256

Well-known member
Local time
Today, 01:21
Joined
Apr 9, 2015
Messages
4,337
vRpt = "rMyReport"
vFile = "c:\folder\" & vOrderNum & vRpt & ".pdf"
docmd.OutputTo acOutputReport ,vRpt,acFormatPDF,vFile
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:21
Joined
Aug 30, 2003
Messages
36,125
There's a little missing from that. More simply:

Code:
DoCmd.OutputTo acOutputReport, Bedfords, acFormatPDF, "C:\exports\" & Me.Customer_Order_Number & ".pdf", True, "", 0
 

lunchbox

New member
Local time
Today, 06:21
Joined
Sep 27, 2017
Messages
5
Thanks for the quick reply guys.

When Im running the script I get 2501 error (Picture attached).

Any Ideas?

Thanks
 

Attachments

  • snip.JPG
    snip.JPG
    15.8 KB · Views: 176

lunchbox

New member
Local time
Today, 06:21
Joined
Sep 27, 2017
Messages
5
Please ignore my last message I has mistyped exports for the actual folder on C.

All is now working thanks so much for your help.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:21
Joined
Aug 30, 2003
Messages
36,125
Make sure the folder exists, and that you have permission to save to it. I assume you're getting the printouts so the report opens okay?
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:21
Joined
Aug 30, 2003
Messages
36,125
Ah, glad you got it sorted.
 

Users who are viewing this thread

Top Bottom