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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Access Report to PDF programmatically..

Status
Not open for further replies.
Oct 13, 2004
39
US
Hello-

I have a MS Access app that has a form with a list of information. There is a preview button on it that calls VB code which appears to generate a Report on the fly. What I am looking for help with is to then take this report and print it to a PDF.

I have run through the process manually and it works using the exact steps above. I then click Print... and select Adobe PDF Writer from the Printer dialog and it creates the document in the location and with the name that I have given it.

This form has 25600 records associated with it so as you can imagine, I would like to automate this process and batch the name and location using a specific naming convention including the ID.

Any suggestions on how to go about this would be greatly appreciated!!!!!!!!!!!!!!!!!!!

Thanks -

Danil
 
Try this from a fellow tek-tiper ... I can't rememebr who


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
 
That looks like a good start but the part taht baffles me is how does this automatically create 25600 of these into new files (with the name that matches the record id) and i cant see where it actually does the saving/printing?

That code seems to set the printer up in the registry and then previews the report and then sets the printe back each time

i am confused - any clarification would be appreciated!! thank you!
 
You will need to run a vba runsql in a loop that creates a report for each record that you want to view then call the print routine from within the loop at each record.
 
Thanks PHV, but I can't get to the topic via your instructions.

The link goes to a forum...not a specific thread :-(
 
PHV said:
and do a keyword search for report pdf loop

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Ahh...I was looking for a thread on that page, Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top