How can I output a report in PDF format, where the name consists of values ​​from fields?

I want to add functionality to my Access 2007 report, whereby a PDF copy of the report is created with the click of a button. I know that there is a macro OutputTothat can do this for me, but it does not allow you to include the values ​​of the report field as part of the name of the PDF file, namely:

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

While I saw this MSDN thread and this SO question , I do not see the field values ​​in any of the answers.

I believe 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

Runtime Error '2465':

Microsoft Office Access cannot find the '|' field mentioned in your expression

Any ideas there?

+5
2

( ).

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] .
+12

, , , .

:

Dim strReportName as String

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

//then try to print strReportName before you use DoCmd.OutputTo.
+1

All Articles