Saving reports as PDF

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

I have some code that will save a report as a pdf
DoCmd.OutputTo acReport, stDocName, acFormatPDF,

The report file name is the name of the report is there a way i can
automaticaly name the file as the OrderNumber the report is based on

Thanks
 
How do you run the report? If you pick an OrderNumber from a combo box on a
form, then you could refer to the combo box as long as the form stays open.
 
How do you run the report? If you pick an OrderNumber from a combo box ona
form, then you could refer to the combo box as long as the form stays open.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.







- Show quoted text -

Yes the form has the order number in me.OrderNumber
 
Yes the form has the order number in me.OrderNumber

So, you can setup the output file name like:

strOutFile = "c:\mypdf\" me.OrderNumber & ".pdf"

docmd.OutputTo acOutputReport,stDocName,acformatpdf, strOutFile

You don't mention if there is some filter on the report. If you need/want to
filter the report, then open the report BEFORE you use the outputTo command.
For example, to filter the report to the current record in the form, you
would go:

me.Refresh
docmd.OpenReport stDocName,acViewPreview,,"id = " & me!id,acHidden
docmd.OutputTo acOutputReport,stDocName,acformatpdf, strOutFile
docmd.Close acReport,stDocName

The above assume the current form has a PK (primary key) of id
 
So, you can setup the output file name like:

  strOutFile = "c:\mypdf\" me.OrderNumber & ".pdf"

docmd.OutputTo acOutputReport,stDocName,acformatpdf, strOutFile

You don't mention if there is some filter on the report. If you need/wantto
filter the report, then open the report BEFORE you use the outputTo command.
For example, to filter the report to the current record in the form, you
would go:

me.Refresh
docmd.OpenReport stDocName,acViewPreview,,"id = " & me!id,acHidden
docmd.OutputTo acOutputReport,stDocName,acformatpdf, strOutFile
docmd.Close acReport,stDocName

The above assume the current form has a PK (primary key) of id

thats perfect, just looked at the code i use to send PDFs by email but
does not let me rename the file name

DoCmd.SendObject acSendReport, "rptOrderacFormatPDF, strTo, , ,
strSubject, strBody, True,
 
Back
Top