Hi,
where can i find a comprehensive example how to use pdfCreator with vba?
Regards
Erwin
Hi,
there is no official example from us available yet but will be included in the next PDFCreator release.
best regards,
Erwin,
Using an example of VB6 code posted by grandzebu code below works in MS Access 2013 with a reference set to PDFCreator.tlb
Steve
Public Function PrintReportPDFCreator(strReportName As String, strFileName As String) As Boolean
Dim OldPrinterName As String, PDFPrintername As String
Dim PDF As PDFCreator.PdfCreatorObj
Dim PDFQueue As New PDFCreator.Queue
Dim MyJob As PDFCreator.PrintJob
Dim PDFDevices As PDFCreator.Printers
Dim objPrn As Printer
'hold old to the default printer for reset at end of procedure
OldPrinterName = Application.Printer.DeviceName
'fire up PDFCreator
Set PDF = New PDFCreator.PdfCreatorObj
'get handle on PDFCreator printer
Set PDFDevices = PDF.GetPDFCreatorPrinters
PDFPrintername = PDFDevices.GetPrinterByIndex(0)
'set PDFCreator printer as current printer
'you could just as easily grab with Application.Printers(“PDFCreator”)
For Each objPrn In Application.Printers
If objPrn.DeviceName = PDFPrintername Then
Set Application.Printer = objPrn
Exit For
End If
Next
'Set PDFQueue = New PDFCreator.Queue
'dimmed as New above so no need for this line above
PDFQueue.Initialize
'it’s important that the report is set to use the default printer, not a specific printer
DoCmd.OpenReport strReportName, acViewNormal
'wait for output
Do Until PDFQueue.Count > 0
DoEvents
Loop
'get a handle on the job and save to filename
Set MyJob = PDFQueue.NextJob
MyJob.SetProfileSetting “OpenViewer”, “False”
MyJob.ConvertTo strFileName
'waiting
Do Until MyJob.IsFinished
DoEvents
Loop
ProcExit:
'reset default printer
For Each objPrn In Application.Printers
If objPrn.DeviceName = OldPrinterName Then
Set Application.Printer = objPrn
Exit For
End If
Next
'close all objects
Set objPrn = Nothing
Set MyJob = Nothing
PDFQueue.ReleaseCom
Set PDFQueue = Nothing
Set PDFDevices = Nothing
Set PDF = Nothing
End Function