Option Compare Database
Option Explicit
Private objPDF As Object
Const strIAProfile As String = "Access Profile"
Const strPDFDriver As String = "novaPDF Pro v5"
Const bIAPublicProfile As Long = 0
Private Sub cmdCreatePDF_Click()
On Error GoTo Error_cmdCreatePDF_Click
Dim strActiveProfile As String
Dim strDefaultPrinter As String
Dim nActiveProfilePublic As Long
' create the NovaPdfOptions object
Set objPDF = CreateObject("novapi.NovaPdfOptions")
' initialize the NovaPdfOptions object
' if you have an application license for novaPDF SDK,
' pass both the registration name and the license key to the Initialize() function
' pNova.Initialize2 strPDFDriver, "<registration name>", "<license key>"
objPDF.Initialize2 strPDFDriver, "", "", ""
' Store the Default Printer. * Note - Access cannot use the objPDF.SetDefaultPrinter command as it does not
' update Access internally fast enough. You must use the Application.Printer command instead.
strDefaultPrinter = Application.Printer.DeviceName
' Get the Active Profile
objPDF.GetActiveProfile2 strActiveProfile, nActiveProfilePublic
' Add new profile
objPDF.AddProfile2 strIAProfile, bIAPublicProfile
With Me
'**************************************************************************************
' Set save options
objPDF.SetOptionLong2 PDF_SAVE_PROMPT, !optSaveOptions, strIAProfile, bIAPublicProfile
objPDF.SetOptionString2 PDF_SAVE_FOLDER, !txtSaveFolder, strIAProfile, bIAPublicProfile
objPDF.SetOptionString2 PDF_SAVE_FILE, !txtFilename, strIAProfile, bIAPublicProfile
objPDF.SetOptionLong2 PDF_SAVE_CONFLICT_STRATEGY, !cboWhenFileExists, strIAProfile, bIAPublicProfile
' After Save Action
objPDF.SetOptionLong2 PDF_ACTION_OPEN_DOCUMENT, !chkOpenViewer, strIAProfile, bIAPublicProfile
objPDF.SetOptionLong2 PDF_ACTION_USE_DEFAULT_VIEWER, !chkOpenViewer, strIAProfile, bIAPublicProfile
' .... other options
' Set the PDF print driver.
objPDF.SetActiveProfile2 strIAProfile, bIAPublicProfile
' Set the Default printer.
Set Application.Printer = Application.Printers(strPDFDriver)
' Run the selected report and create a PDF file.
DoCmd.OpenReport "rptSMZipCode"
' Return to previous settings
objPDF.SetActiveProfile2 strActiveProfile, nActiveProfilePublic
objPDF.DeleteProfile2 strIAProfile, bIAPublicProfile
' Restore the Default Printer.
Set Application.Printer = Application.Printers(strDefaultPrinter)
End With
Exit_cmdCreatePDF_Click:
Set objPDF = Nothing
Exit Sub
Error_cmdCreatePDF_Click:
Debug.Print Err.Number & ":" & Err.Description
Resume Next
End Sub