我想向我的 Access 2007 报告添加功能,通过单击按钮创建报告的 PDF 副本。我知道有一个 OutputTo
可以为我执行此操作的宏,但它不允许我将报告字段值作为 PDF 文件名的一部分包含在内,即:
[Client Organisations].Code + "-" + Clients.Code + "-" + Invoices_Code + "-" + Format([Invoice Date],"yyyy") + ".pdf"
虽然我看过这个 MSDN thread而这个 SO question ,我在任何答案中都没有看到使用字段值。
我认为 VBA 代码是可行的方法,所以我(未成功)尝试了以下操作:
Private Sub Create_PDF_Click()
DoCmd.OutputTo acOutputReport, , acFormatPDF, "" + [Client Organisations].Code
+ "-" + Clients.Code + "-" + Invoices_Code + "-" + Format([Invoice Date],"yyyy")
+ ".pdf", True
End Sub
Run-time error '2465':
Microsoft Office Access can't find the field '|' referred to in your expression
有什么想法吗?
最佳答案
我让它工作(最终)。
以下sub
做到了:
Private Sub Create_PDF_Click()
Dim myPath As String
Dim strReportName As String
DoCmd.OpenReport "Invoices", acViewPreview
myPath = "C:\Documents and Settings\"
strReportName = Report_Invoices.[Client Organisations_Code] + "-" +
Report_Invoices.Clients_Code + "-" + Report_Invoices.Invoices_Code + "-" +
Format(Report_Invoices.[Invoice Date], "yyyy") + ".pdf"
DoCmd.OutputTo acOutputReport, "", acFormatPDF, myPath + strReportName, True
DoCmd.Close acReport, "Invoices"
End Sub
两个注意事项:
[Client Organisations].Code
是 [Client Organisations_Code]
在报告中。 关于vba - 如何以 PDF 格式输出报告,其中名称由字段中的值组成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2296884/