问题
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