Simple VBA code to export Access Report to saved PDF File when code is run

匆匆过客 提交于 2019-12-13 13:23:29

问题


I'm looking for a very simple solution here. I simply want a vba script that I can run over and over again to save the same Access report (that changes as the weeks go by) into the same file over and over again. I need it to be the same name each time and don't want to be prompted that the filename is already there. In my research, it feels like the following should work but it does not. Can anyone provide a simple script that performs this task?

 Sub program()
 DoCmd.OutputTo acOutputReport, "Employee1",  
 acFormatPDF,"C:\Users\desktop\PDFs\Report1.pdf"
 End Sub

回答1:


Add a line continuation character (underscore: _) to indicate the line following DoCmd.OutputTo should be considered part of the same logical instruction:

DoCmd.OutputTo acOutputReport, "Employee1", _ 
acFormatPDF,"C:\Users\desktop\PDFs\Report1.pdf"

The line continuation character must be preceded by at least one space, and there can be no characters after the line continuation.



来源:https://stackoverflow.com/questions/34799300/simple-vba-code-to-export-access-report-to-saved-pdf-file-when-code-is-run

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