访问VBA输出到pdf“输出到”提示

时间:2013-10-29 14:25:39

标签: vba ms-access pdf ms-access-2007 access-vba

我在Access 2007 SP3中遇到了一个奇怪的问题。当我将报告导出为pdf时,我得到了“输出到”提示,这是我不想要的,我的代码中有什么东西我做错了吗?

OverViewFile = DLookup("ExportPath", "dbo_Defaults") & "PC" & Format(Now(), "ddmmyy") & Format(Now(), "hhmm") & ".pdf"

DoCmd.OutputTo acOutputReport, "Rpt_ExportBPC", acFormatPDF, OverViewFile, False

如果我错过了什么,请告诉我。

1 个答案:

答案 0 :(得分:1)

在使用我的报告对象的名称调整OutputTo并为其提供 OverViewFile 的有效文件路径时,我没有从Access 2007 SP3获得该提示。所以我怀疑你的问题是由于 OverViewFile ;检查该字符串的值:

OverViewFile = DLookup("ExportPath", "dbo_Defaults") & "PC" & Format(Now(), "ddmmyy") & Format(Now(), "hhmm") & ".pdf"
Debug.Print OverViewFile
DoCmd.OutputTo acOutputReport, "Rpt_ExportBPC", acFormatPDF, OverViewFile, False

您可以在立即窗口中查看Debug.Print的输出( Ctrl + g 将带您到那里)。

也许DLookup正在返回Null。然后,您将拥有 OverViewFile 的有效VBA字符串,但它不是有效的Windows路径。

OverViewFile 还有另一个问题,可能不会导致问题,但我会建议这样做因为它更简单,我认为你实际上想要 hhnn hhmm 在文件名中( n 代表分钟; m 代表月份)

OverViewFile = DLookup("ExportPath", "dbo_Defaults") & "PC" & _
    Format(Now(), "ddmmyyhhnn") & ".pdf"