Limited time promo

Access Sample - PDF Reports

English

This help topic applies only to novaPDF. If you don't have it yet, you must download it first.

Download now Buy licenses
Mar 22, 2022
novaPDF 11.x
We strive to keep our help as accurate as possible. If you notice any inconsistencies or outdated info please let us know.
PDF Reports Sample is an Access database with one table and one form. On the form you can set several options for the novaPDF SDK and then press a button to generate a PDF file. A report is made on the table and it is sent to novaPDF SDK.
It demonstrates the basic use of the INovaPDFOptions interface. The printing job is made using the object "Application.Printer"
Basically the sample creates a new profile called "Access Profile", sets the new profile as active, sets the user options from form controls, opens and prints a report, and restores original printer settings.

Source code

Option Compare Database
Option Explicit
Private objPDF As Object
Const strIAProfile As String = "Access Profile"
Const strPDFDriver As String = "novaPDF SDK"
Const bIAPublicProfile As Long = 0
Private Sub cmdCreatePDF_Click()
On Error GoTo Error_cmdCreatePDF_Click
Dim strActiveProfileId As String
Dim strNewProfileId As String
Dim strDefaultPrinter As String
' create the NovaPdfOptions object
Dim objPDF As New NovaPdfOptions11
' initialize the NovaPdfOptions object to use with a printer licensed for SDK
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 strActiveProfileId
' Add new profile
objPDF.AddProfile2 strProfileName, bIAPublicProfile, strNewProfileId
'Load the profile
objPDF.LoadProfile2 strNewProfileId
With Me
'************************************************************************************************************************
' Set save options
If !optSaveOptions Then
objPDF.SetOptionLong NOVAPDF_SAVE_PROMPT_TYPE, PROMPT_SAVE_EXTENDED
Else
objPDF.SetOptionLong NOVAPDF_SAVE_PROMPT_TYPE, PROMPT_SAVE_NONE
End If
objPDF.SetOptionLong NOVAPDF_SAVE_FOLDER_TYPE, SAVEFOLDER_CUSTOM
objPDF.SetOptionString2 NOVAPDF_SAVE_FOLDER, !txtSaveFolder
objPDF.SetOptionString2 NOVAPDF_SAVE_FILE_NAME, !txtFilename
objPDF.SetOptionLong NOVAPDF_SAVE_FILEEXIST_ACTION, !cboWhenFileExists
' After Save Action
objPDF.SetOptionBool NOVAPDF_ACTION_DEFAULT_VIEWER, !chkOpenViewer
'.... other options
'save options
objPDF.SaveProfile
' Set the PDF print driver.
objPDF.SetActiveProfile2 strNewProfileId
' 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 strActiveProfileId
objPDF.DeleteProfile2 strNewProfileId
' 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