Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access 97 Report To PDF Via VB Code

Status
Not open for further replies.

SgtJarrow

Programmer
Apr 12, 2002
2,937
US
I have developed an invoice system for my client. The invoices created are currently previewed and then "printed" with Acrobat PDFWriter/Acrobet Distiller. These saved files are then emailed as necessary.

The problem lies in the fact that sometimes there may be several hundred to run at one time. This is very time consuming. Each report can be uniquely identified so the name of the saved file is fully flexible. (The system prior to this used a For Each Loop with DoCmd.OutputTo to save each in succession.

The client does not want to have any user intervention in the saving of the files. They want to be able to click a button to generate the invoices and then end product be a number of .pdf files in a directory.

What I am ultimately looking for is a DoCmd.OutpuTo type command line for saving reports as a .pdf files. I have searched the forums and found nothing to help. I have found one refeence to changing the default printer, runnig all the reports, then changing the printer back, bu would like to avoid this if possible. I have also already tried using acFormatPDF in the DoCmd.OutputTo line, ensuring that the appropriate PDF references were added to the References selection.

Any one have any ideas? The secret to creativity is knowing how to hide your sources. - Albert Einstein [spin]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Here is some code that I found on the internet last nite relative to this issue.....

I have not tried it yet, so I am not sure how it works.

Let me know if it helps.



Output a report in PDF format
faq705-1635
The following code will output an Access report as a PDF file.

You’ll need:
- the Acrobat PDFWriter software on your machine.
- Your own version of the Get/Save registry setting calls below

Note: this is a chopped down version of my real code just to show the salient points. You’ll need to adapt this to your own context.

Public Sub RunReportAsPDF
On Error GoTo Err_RunReport

‘ Folder where PDF file will be written
sPDFPath = “C:\myapp\archive\”

‘ Save current default printer
sMyDefPrinter = GetRegistryString(HKEY_CURRENT_USER, "Software\Microsoft\WIndows NT\CurrentVersion\Windows", "Device")
‘ Set default printer to PDF Writer
SaveRegistryString HKEY_CURRENT_USER, "Software\Microsoft\WIndows NT\CurrentVersion\Windows", "Device", "Acrobat PDFWriter"

sPDFName = “myReport.pdf"
‘ Setting value for PDFFileName in the registry stops file dialog box from appearing
SaveRegistryString HKEY_CURRENT_USER, "Software\Adobe\Acrobat PDFWriter", "PDFFileName", sPDFPath + sPDFName

‘ Run the report
DoCmd.OpenReport “myReport”, acPreview

Exit_RunReport:
' Restore default printer
SaveRegistryString HKEY_CURRENT_USER, "Software\Microsoft\WIndows NT\CurrentVersion\Windows", "Device", sMyDefPrinter
Exit Sub

Err_RunReport:
MsgBox Err.Description
Resume Exit_RunReport

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top