如何以PDF格式输出报告,其中名称由字段中的值组成? [英] How can I output a report in PDF format, where the name consists of values from fields?

查看:77
本文介绍了如何以PDF格式输出报告,其中名称由字段中的值组成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向我的Access 2007报表添加功能,从而可以通过单击按钮来创建报表的PDF副本.我知道有一个OutputTo宏可以为我完成此操作,但是它不允许我将报告字段值作为PDF文件名的一部分包括在内,即

I want to add functionality to my Access 2007 report whereby a PDF copy of the report is created at the click of a button. I know that there is an OutputTo macro which can do this for me, but it does not allow me to include report field values as part of the PDF's filename, namely:

[Client Organisations].Code + "-" + Clients.Code + "-" + Invoices_Code + "-" + Format([Invoice Date],"yyyy") + ".pdf"

虽然我看到了这个 SO问题,我在任何答案中都看不到字段值的使用.

While I have seen this MSDN thread and this SO question, I don't see the use of field values in any of the answers.

我认为应该使用VBA代码,所以我(未成功)尝试了以下操作:

I reckon VBA code is the way to go, so I (unsuccessfully) tried the following:

Private Sub Create_PDF_Click()
DoCmd.OutputTo acOutputReport, , acFormatPDF, "" + [Client Organisations].Code  
+ "-" + Clients.Code + "-" + Invoices_Code + "-" + Format([Invoice Date],"yyyy")
+ ".pdf", True
End Sub

运行时错误"2465":

Run-time error '2465':

Microsoft Office Access找不到字段"|"表达式中提到的

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

两个警告:

  1. 需要在打印之前打开报告.
  2. 请使用与报表所看到的名称相同的名称来引用字段.报告中的[Client Organisations].Code[Client Organisations_Code].

这篇关于如何以PDF格式输出报告,其中名称由字段中的值组成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆