I have the following code to save a report as a PDF from my Access form:
The issue I'm having is that after I click the command button to save the report as a PDF, the PDF is automatically opened. I have to run this process for 40-60 employees...I don't want 40-60 PDF files opened on my computer at once.
This code has to remain the same, as it is the only way I have been able to save a report as a PDF with a dynamic naming convention, so the acViewNormal portions cannot be changed to acHidden, or the caption section of the code wouldn't apply (at least I think that would break it, idk.. I'm new to Access).
Is there anything I could add to the end of this code to close the PDF that was just created? It has to open for the name to generate in the 'Save As' dialogue box, but how can I close it automatically?
Thanks in advance.
Code:
Private Sub btnPrint_PDF_Click()
Dim strDefaultPrinter As String
Dim stDocName As String
strDefaultPrinter = Application.Printer.DeviceName
stDocName = "Sales_Incentive_Report"
Set Application.Printer = Application.Printers("PDF Printer")
DoCmd.OpenReport "Sales_Incentive_Report", acViewDesign, , , acHidden
Reports!Sales_Incentive_Report.Caption = LastName & "_Sales_Incentive_Report"
DoCmd.Close acReport, "Sales_Incentive_Report", acSaveYes
DoCmd.OpenReport stDocName, acViewNormal
DoCmd.Close acReport, "Sales_Incentive_Report"
End Sub
The issue I'm having is that after I click the command button to save the report as a PDF, the PDF is automatically opened. I have to run this process for 40-60 employees...I don't want 40-60 PDF files opened on my computer at once.
This code has to remain the same, as it is the only way I have been able to save a report as a PDF with a dynamic naming convention, so the acViewNormal portions cannot be changed to acHidden, or the caption section of the code wouldn't apply (at least I think that would break it, idk.. I'm new to Access).
Is there anything I could add to the end of this code to close the PDF that was just created? It has to open for the name to generate in the 'Save As' dialogue box, but how can I close it automatically?
Thanks in advance.