Saving a report as PDF (1 Viewer)

Andyrew21

New member
Local time
Yesterday, 23:43
Joined
Aug 4, 2017
Messages
4
i have written some VBA to save a report as PDF, its pretty basic but gets the Job done,

Code:
Private Sub SavePDFbttn_Click()

Dim MyPath As String
Dim MyFilename As String

MyPath = "C:\Data\RFP PO\"
MyFilename = "RFPPO" + ".pdf"



DoCmd.OpenQuery "qry_full_po_details_by_PO"
DoCmd.OpenReport "Report2", acViewPreview
DoCmd.OutputTo acOutputReport, report2, acFormatPDF, MyPath & MyFilename, True
DoCmd.Close acReport, "Report2"
DoCmd.Close acQuery, "qry_full_po_details_by_PO"





End Sub

Issue i am having is naming the PDF a unique Value, Ideally i would like to name is with the delivery warehouse, Vendor name & PO Name from the "report2" fields but i am stuck on how to get this to work, i can only manage a basic string

any help would be great as i am self taught and completely new to this, Normally google saves but i dont know if i am just snow blind but i cant find an answer

thanks
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 23:43
Joined
Aug 30, 2003
Messages
36,137
If the values are on this form:

MyFilename = "RFPPO" & Me.TextboxName & ".pdf"

By the way, you normally don't need to open the query or the report to output it. Try with just the output line.
 

156sting

Registered User.
Local time
Today, 14:43
Joined
Aug 23, 2012
Messages
28
just like pbaldy said, you need to take the names you want from a form.

i have recently done this myself (and just like you im still learning)

Code:
Dim TheFileDir
Dim Warehouse
Dim PONum
Dim TheFileName As String

 
TheFileDir = "Z:\Documents\Invoices\"  
Warehouse = Me.txtTheWarehouse & " "
PONum = Me.txtPONum & ".pdf"

TheFileName = TheFileDir & Warehouse & PONum

DoCmd.OutputTo acOutputReport, "REPORTNAME", acFormatPDF, TheFileName

Warehouse and PONum are coming from the form you create.

hope this helps
 

Andyrew21

New member
Local time
Yesterday, 23:43
Joined
Aug 4, 2017
Messages
4
Ok so i need to make a form first and then a report?

what i have done is create a Query the created a form where i input a from and to date, this returns all PO numbers in that period.

then i have a Report that uses the selected po number in the PO number list to create the report.

i am then adding a button where i can out put the report to a PDF and save it.

i have changed the code like you said and i am getting an Compile Error, Method or data member not found.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 23:43
Joined
Aug 30, 2003
Messages
36,137
You don't need to use a form, but most of us use one to gather user input. Did you change the code to reflect your textbox name(s)?
 

Users who are viewing this thread

Top Bottom