Please enable JavaScript to view this site.

Navigation: Developer Information > Programming Environments

Microsoft Access

Scroll Prev Top Next More

The following example shows the basic code to open and print an Access report to Win2PDF. This example uses SaveSetting to set the PDF file name and will suppress the Win2PDF File Save window.

 

Private Sub cmd_PrintToWin2PDF_Click()

 

'This code assumes that Win2PDF is set as the default printer.

On Error GoTo Err_cmd_PrintToWin2PDF_Click

 

 Dim stDocName As String

 

 'set the output file name

 SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFFileName", "c:\temp\AccessTest.pdf"

 

 stDocName = "Report to be converted"

 DoCmd.OpenReport stDocName, acNormal

 

Exit_cmd_PrintToWin2PDF_Click:

 Exit Sub

 

Err_cmd_PrintToWin2PDF_Click:

 MsgBox Err.Description

 Resume Exit_cmd_PrintToWin2PDF_Click

 

End Sub

 

The following example shows how to merge two Access reports into a single PDF file:

 

 

 'This sample assumes that Win2PDF is set as the default printer.

 

 'create first PDF file from report rpt_OriginalReport

 SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFFileName", "c:\temp\Report.pdf"

 DoCmd.OpenReport "rpt_OriginalReport", acNormal

 

 'Set registry to append 2nd report to PDF file just created

 SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFFileName", "c:\temp\MergedReports.pdf"

 SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFPrependFile", "c:\temp\Report.pdf"

 

 'print second report, rpt_ReportToAppend

 DoCmd.OpenReport "rpt_ReportToAppend", acNormal

 

 

The following sample shows how to email without user interaction using the Win2PDF Mail Helper application. You need to install and configure the Win2PDF Mail Helper application before running this code.

 

The SaveWin2PDFDword routine used in this example is listed in Using the Printer object.

 

 

 'This sample assumes that Win2PDF is set as the default printer.

 

 Dim stDocName As String

 

 'enable sending the PDF file with no user interaction

 SaveWin2PDFDword "file options", &H420

 

 'set the output file name

 SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFFileName", txt_PDFFileName

 

 SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFMailRecipients", txt_emailaddress

 SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFMailSubject", txt_EmailSubject

 SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFMailNote", txt_emailmessage

 

 stDocName = "rpt_Report_to_EMail"

 DoCmd.OpenReport stDocName, acNormal