如何使用从报告中提取的自定义名称保存访问报告?

时间:2013-04-03 15:10:24

标签: access-vba

我需要使用自定义名称保存PDF文件。此名称应包含报告中的参数/值。

我需要生成这样的几个报告,所以我需要区分,我想Member_ID字段将提供。我在网上搜索了很多,但我无法实现任何一项。

我现在的代码如下:

Private Sub Create_PDF_Click()

Dim myPath As String Dim strReportName As String

DoCmd.OpenReport "Proof_Graphs", acViewPreview

myPath = "C:\Proofs\"

strReportName = Proof_Graphs.[MEMBER_ID] + "-" + ".pdf"

DoCmd.OutputTo acOutputReport, "", acFormatPDF, myPath + strReportName, True DoCmd.Close acReport, "Proof_Graphs"

End Sub

我收到一个找不到错误的对象。

1 个答案:

答案 0 :(得分:0)

你可以使用 Reports!ReportName!FieldName访问控制框以获取报告中的值。

Private Sub Create_PDF_Click()
Dim myPath As String Dim strReportName As String
Dim memberID As String

DoCmd.OpenReport "Proof_Graphs", acViewPreview

memberID = Reports!Proof_Graphs.[MEMBER_ID]'to access the field for the value on the report

myPath = "C:\Proofs\"

strReportName = memberID +  ".pdf"

DoCmd.OutputTo acOutputReport, "", acFormatPDF, myPath + strReportName, True DoCmd.Close acReport, "Proof_Graphs"

End Sub