Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

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

© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer