Print Reports to PDF Programmatically..

CliffHanger9

zigga zigga
Local time
Today, 10:04
Joined
Nov 1, 2004
Messages
20
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
 
Reports: Save a report's output as a PDF file*
Author(s)
Keri Hardwick


If you have Adobe Acrobat installed on your machine, you can output a report to a PDF file for viewing and easier electronic distribution to users.
Follow these steps to get the various pieces together.

Buy and install Acrobat on the machine(s) where the reports will be created.
In your Winini file, add a section like this, if it doesn't already exist:
[Acrobat PDFWriter]
PDFFilename=C:\(path)\pdftemp.doc
bDocInfo=0

If this section does not exist, create it. Put it right after the [Ports] section. The file name line will get your path and pdffilename; the bDocInfo line sets a switch so that you won't get the dialogbox when you print to pdf.

Download defaultprt.zip. This zip file contains code for changing the default printer that Ken Getz has posted. Import the modules into your db.
Add a new module and add this code (or put this code in an existing module).
The legal stuff:
THE CODE CANNOT BE USED WITHOUT THE COPYRIGHT INFORMATION, AND YOU MAY NOT MODIFY THE EXISTING CODE. ADD WHATEVER CODE YOU LIKE, IF YOU NEED, BUT LEAVE THE EXISTING CODE INTACT.

Option Compare Database
Option Explicit
' These functions used with procedures from
' Microsoft Access 95 How-To
'(c) 1998 Ken Getz and Paul Litwin
' All rights reserved.

' Other modules from this source are:
' basDefaultPrinter
' basGetPrinters
' basIniFile
' basPrintTypes
' basToken

' You'll also need defaultprt.zip

Private drexisting As aht_tagDeviceRec
Const AcrobatName = "Acrobat PDFWriter"
Const AcrobatDriver = "PDFWRITR"
Const AcrobatPort = "LPT1:"
Sub ResetDefaultPrinter()
Call ahtSetDefaultPrinter(drexisting)
End Function
Function ChangeToAcrobat()
If ahtGetDefaultPrinter(drexisting) Then
Dim dr As aht_tagDeviceRec
With dr
.drDeviceName = AcrobatName
.drDriverName = AcrobatDriver
.drPort = AcrobatPort
End With
Call ahtSetDefaultPrinter(dr)
End If
End Function

Sub ChangePdfFileName(NewFileName As String)
Call aht_apiWriteProfileString("Acrobat PDFWriter", _
"PDFFileName", NewFileName)
End Sub


Create the print file. To do this, add the following lines to the appropriate place in your code (perhaps in reaction to a button click):
ChangeToAcrobat
ChangePdfFileName "Name of pdf file including .pdf"
DoCmd.OpenReport "YourReportName", acViewNormal
ResetDefaultPrinter
*DefaultPrt.zip, which you can download from the www.mcwtech.com site, does exactly what it was intended to do, for the purpose for which it was intended. There is no explicit support in that download for Adobe Acrobat, and you may need information available on the Adobe support web site for using their printer services with any other product. Please do not send email requesting support on the use of DefaultPrt.zip with Adobe Acrobat, as none can be supplied. (In our experience, the instructions listed here work fine for some versions of Acrobat, but not for others, as Adobe appears to have changed their programmatic interface. For more information on making this tip work in your own environment, stop by www.adobe.com.)
 
Liv Manto said:
In your Winini file, add a section like this, if it doesn't already exist:
[Acrobat PDFWriter]
PDFFilename=C:\(path)\pdftemp.doc
bDocInfo=0

If this section does not exist, create it. Put it right after the [Ports] section. The file name line will get your path and pdffilename; the bDocInfo line sets a switch so that you won't get the dialogbox when you print to pdf.

Can this be set and then deleted programatically?
 

Users who are viewing this thread

Back
Top Bottom