Come posso output di un report in formato PDF, in cui il nome è costituito da valori dai campi?

StackOverflow https://stackoverflow.com/questions/2296884

  •  21-09-2019
  •  | 
  •  

Domanda

Voglio aggiungere funzionalità alla mia relazione Access 2007 in cui viene creata una copia PDF del report con un clic di un pulsante. So che c'è una macro OutputTo che può fare questo per me, ma non mi permette di includere i valori dei campi report come parte del nome del file PDF, vale a dire:

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

Mentre ho visto questo MSDN filo e questo domanda SO , ho non si vede l'uso di valori di campo in una qualsiasi delle risposte.

Mi sa codice VBA è la strada da percorrere, quindi (senza successo) provato quanto segue:

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

Errore di run-time '2465':

     

Microsoft Office Access non riesce a trovare il campo '|' di cui alla vostra espressione

Tutte le idee là fuori?

È stato utile?

Soluzione

ho preso al lavoro (eventualmente).

Il seguente sub ha fatto il trucco:

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

Due avvertimenti:

  1. Il rapporto deve essere aperto prima della stampa.
  2. Fare riferimento ai campi con lo stesso nome che la relazione vede come. Quella è stata [Client Organisations].Code [Client Organisations_Code] nel rapporto.

Altri suggerimenti

La sua più facile da Dim una stringa e mettere la vostra intera espressione lì e poi eseguire il debug per vedere se contiene il nome del report valido.

In questo modo:

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.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top