Here's some old PDF printing code I found in my archives. It's something to get you started but you'll need to research this more. Note that using this code (ie. Set Application.Printer = Application.Printers("Adobe PDF")) you can also change the printer to another printer other than "Adobe PDF". Also note that to utilize the PDF driver, besides "Adobe PDF", it could be "Adobe Writer" or "Adobe Distiller" or "Acrobrat Writer" (I can't remember which one) but it depends on which PDF driver you are utilizing and version of PDF you have installed. Adobe has this frustrating thing where they change the PDF driver name with different versions of PDF (frustrating as h#@@.) I might not recommend using the "Adobe Distiller" driver as I've had problems using that driver in the past. I believe "Adobe PDF" was the best thing for me to use but yours will again be dependant upon what you have installed for creating PDFs. Hope this helps. I believe the "Leban" website has some more specific examples for outputting to a PDF file.
Public Function RunReportAsPDF(prmRptName As String, prmPdfName As String, UniqueID As Integer) As Boolean
' Returns TRUE if a PDF file has been created
Dim AdobeDevice As String
Dim strDefaultPrinter As String
'Find the Acrobat PDF device
AdobeDevice = GetRegistryValue(HKEY_CURRENT_USER, "Software\Microsoft\WIndows NT\CurrentVersion\Devices", "Adobe PDF")
If AdobeDevice = "" Then ' The device was not found
MsgBox "You must install Acrobat Writer before using this feature"
RunReportAsPDF = False
' get current default printer.
strDefaultPrinter = Application.Printer.DeviceName
Set Application.Printer = Application.Printers("Adobe PDF")
'Create the Registry Key where Acrobat looks for a file name
CreateNewRegistryKey HKEY_CURRENT_USER, "Software\Adobe\Acrobat Distiller\PrinterJobControl"
'Put the output filename where Acrobat could find it
SetRegistryValue HKEY_CURRENT_USER, "Software\Adobe\Acrobat Distiller\PrinterJobControl", Find_Exe_Name(CurrentDb.Name, CurrentDb.Name), prmPdfName
On Error GoTo Err_handler
'Run the report (Note : I amended this code to filter the report for the unique ID)
DoCmd.OpenReport prmRptName, acViewNormal, , "[Unique_id] = " & UniqueID
While Len(Dir(prmPdfName)) = 0 ' Wait for the PDF to actually exist
RunReportAsPDF = True ' Mission accomplished!
Set Application.Printer = Application.Printers(strDefaultPrinter) ' Restore default printer
On Error GoTo 0
If Err.Number = 2501 Then ' The report did not run properly (ex NO DATA)
RunReportAsPDF = False
RunReportAsPDF = False ' The report did not run properly (anything else!)
MsgBox "Unexpected error #" & Err.Number & " - " & Err.Description
Last edited by pkstormy; 10-30-08 at 01:19.
Expert Database Programming
MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)