Access VBA - Export Access Form to PDF then Close the Adobe Reader

Deadly 提交于 2019-12-24 03:07:40

问题


I have a VBA code in Access that exports/saves 3 seperate Access Forms to a PDF for record purposes. However, upon completion, Adobe Reader opens the Forms that were saved, requiring the processor to manually close all 3 forms. 3 forms doesn't sound like much but they will be completing this process continuously for all 239 of our entities! This means they will have to manually click Close over 700 times a day! So much for efficiency.

Is there a VBA code to close the PDF in Adobe Reader?

Below is the code that I am currently using:

Private Sub Command4_Click()
DoCmd.SetWarnings False

DoCmd.OpenQuery "Add to Completed", acViewNormal
DoCmd.OpenQuery "Clear from Master", acViewNormal
DoCmd.OpenQuery "Completed Totals", acViewNormal
DoCmd.OpenQuery "Update AB Totals", acViewNormal
DoCmd.OpenQuery "Update CD Totals", acViewNormal
DoCmd.OpenQuery "Update EF Totals", acViewNormal
DoCmd.OpenQuery "Update YTD Total", acViewNormal

DoCmd.OpenForm "Form123-pg1", acPreview
DoCmd.PrintOut acPrintAll
**DoCmd.OutputTo acOutputForm, "Form123-pg1", acFormatPDF, "Z:\Corporate\SubProcess\2014\" & Format(Date - 30, "mmyy") & " - " & [Forms]![Deal_Nav]![cbo_UnitNo] & " ReportName Pg1.pdf", True**
DoCmd.Close acForm, "Form123-pg1", acSaveNo
DoCmd.OpenForm "Form123-pg2", acPreview
DoCmd.PrintOut acPrintAll
**DoCmd.OutputTo acOutputForm, "Form123-pg2", acFormatPDF, "Z:\Corporate\SubProcess\2014\" & Format(Date - 30, "mmyy") & " - " & [Forms]![Deal_Nav]![cbo_UnitNo] & " ReportName Pg2.pdf", True**
DoCmd.Close acForm, "Form123-pg2", acSaveNo
DoCmd.OpenForm "Form123-pg3", acPreview
DoCmd.PrintOut acPrintAll
**DoCmd.OutputTo acOutputForm, "Form123-pg3", acFormatPDF, "Z:\Corporate\SubProcess\2014\" & Format(Date - 30, "mmyy") & " - " & [Forms]![Deal_Nav]![cbo_UnitNo] & " ReportName Pg3.pdf", True**
DoCmd.Close acForm, "Form123-pg3", acSaveNo

Me.Requery
Me.Refresh
DoCmd.SetWarnings True

End Sub


回答1:


Acrobat opens after creating your pdf because you tell it to.

DoCmd.OutputTo acOutputForm, "Form123-pg1", acFormatPDF, "Z:\Corporate\SubProcess\2014\" & Format(Date - 30, "mmyy") & " - " & [Forms]![Deal_Nav]![cbo_UnitNo] & " ReportName Pg1.pdf", True

If you change the AutoStart Flag from True to False then it won't and you don't have to close anything.

DoCmd.OutputTo acOutputForm, "Form123-pg1", acFormatPDF, "Z:\Corporate\SubProcess\2014\" & Format(Date - 30, "mmyy") & " - " & [Forms]![Deal_Nav]![cbo_UnitNo] & " ReportName Pg1.pdf", False

Now Docmd.OutputTo will just create the file.



来源:https://stackoverflow.com/questions/26518833/access-vba-export-access-form-to-pdf-then-close-the-adobe-reader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!