Saving reports as PDF

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
 
J

Jerry Whittle

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.
 
S

Simon

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
 
A

Albert D. Kallal

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
 
S

Simon

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top