运行代码时将访问报告导出到保存的 PDF 文件的简单 VBA 代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34799300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:10:27  来源:igfitidea点击:

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

vbams-accessaccess-vba

提问by Bouje

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?

我在这里寻找一个非常简单的解决方案。我只是想要一个 vba 脚本,我可以一遍又一遍地运行它来一遍又一遍地将相同的 Access 报告(随着时间的推移而变化)保存到同一个文件中。我每次都需要它的名称相同,并且不想被提示文件名已经存在。在我的研究中,感觉以下应该有效,但事实并非如此。谁能提供一个简单的脚本来执行这个任务?

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

回答by HansUp

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

添加行继续符(下划线:)_以指示DoCmd.OutputTo应将以下行视为同一逻辑指令的一部分:

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.

续行符前面必须至少有一个空格,并且续行符后面不能有任何字符。