[AccessD] Copy an Access report to pdf file on harddrive

Jim Dettman jimdettman at earthlink.net
Tue Dec 27 09:01:01 CST 2005


Lonnie,

  You can use an Acrobat product and print to a file using the Acrobat PDF
printer driver or use one of the 3rd party tools floating around out there.
There is PDFPrint from ATTAC Consulting (makers of On The Fly Printing) or
one that's quite popular and I use is Ghost
Script(http://www.cs.wisc.edu/~ghost/).

  Below is the code I use to output to a file with Ghost Script.  The basic
technique is to output to a file, script a batch file to call GS, then
execute the batch and have GS do the translation to PDF.

HTH,
Jim.

Function RunReportAsPDF(strReportName As String) As String

        ' Prints a report to disk
        ' and then converts to a PDF file with Ghost Script.
        ' Returns name of file if sucessfull
        ' empty string ("") if not.
        Const RoutineName = "RunReportAsPDF"
        Const Version = "1.0"

        Dim strPDFPrinter As String
        Dim strPDFProgPath As String
        Dim strPDFFileName As String
        Dim strPRNFile As String
        Dim lngHWnd As Long

10      On Error GoTo RunReportAsPDF_Error

20      RunReportAsPDF = ""

30      strPDFPrinter = GetAppConfigValue(AppShortName(), "PDFPrinter", ".",
".")
40      strPDFProgPath = GetAppConfigValue(AppShortName(), "PDFProgPath",
".", ".")
50      strPRNFile = GetAppConfigValue(AppShortName(), "PDFPrnFile ", ".",
".")

        ' Kill the printer output file if it already exists.
60      If (Dir(strPRNFile) & "" <> "") Then
70        On Error Resume Next
80        Kill strPRNFile
90        On Error GoTo RunReportAsPDF_Error
100     End If

        ' Now run the report
110     If SetDefaultPrinter(strPDFPrinter) = True Then
120       DoCmd.OpenReport strReportName, acViewNormal

          ' Wait until the report completes
130       Do While Dir(strPRNFile) & "" = ""
140         DoEvents
150       Loop

160       Call ResetDefaultPrinter(0)

          'Generate file name to use for PDF output
170       strPDFFileName = GetTempFileName_TSB(AppShortName())
180       strPDFFileName = Replace(strPDFFileName, ".tmp", ".pdf")

          ' Change printer driver output into a PDF
          ' Script the batch file
190       Open strPDFProgPath & "MKPDF.bat" For Output As #1
200       Print #1, "" & left(strPDFProgPath, 2)
210       Print #1, "" & "CD " & Chr(34) & Mid(strPDFProgPath, 3) & Chr(34)
220       Print #1, "" & Chr(34) & strPDFProgPath & "MAKEPDF" & Chr(34) & "
" & strPRNFile & " /D /V1.4 /O" & strPDFFileName
230       Close #1

          ' Execute batch file
240       strPDFProgPath = Chr(34) & strPDFProgPath & "MKPDF.bat" & Chr(34)
250       lngHWnd = Shell(strPDFProgPath, vbMinimizedNoFocus)

          ' and wait till done.
260       WaitWhileRunning (lngHWnd)

270       RunReportAsPDF = strPDFFileName

280     Else
290       gstrMBTitle = "Printer not installed."
300       gstrMBMsg = "The printer " & strPDFPrinter & " is not installed."
310       gstrMBMsg = gstrMBMsg & vbCrLf & "Please correct."
320       gintMBDef = vbCritical + vbOKOnly
330       gintMBBeep = True
340       gintMBLog = True
350       Call DisplayMsgBox
360       RunReportAsPDF = ""
370     End If

RunReportAsPDF_Exit:

380     Exit Function

RunReportAsPDF_Error:
390     UnexpectedError ModuleName, RoutineName, Version, Err.Number,
Err.Description, Err.Source, VBA.Erl
400     RunReportAsPDF = ""
410     Resume RunReportAsPDF_Exit

End Function



-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Lonnie Johnson
Sent: Tuesday, December 27, 2005 9:37 AM
To: AccessD solving'
Subject: [AccessD] Copy an Access report to pdf file on harddrive


How can I accomplish this via code without any user intervention?



May God bless you beyond your imagination!
Lonnie Johnson
ProDev, Professional Development of MS Access Databases
Visit me at ==> http://www.prodev.us












---------------------------------
Yahoo! Shopping
 Find Great Deals on Holiday Gifts at Yahoo! Shopping
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list