doCmd print to pdf syntax using a field ref in the file name string (1 Viewer)

Binworkin

New member
Local time
Today, 09:53
Joined
Jun 6, 2020
Messages
9
I am using the following to print a report in pdf to a location on my C drive. A query on which the report is based has a field called [FileNamePart] in [qryLaborCostData].

I would like the file name to be "Task Detail" & [FilenamePart] & ".pdf"

Code:
Private Sub Command6_Click()

DoCmd.OutputTo acOutputReport, "Task_Detail", acFormatPDF, "C:\Users\SH\Production\" & "Task Detail" & [qryLaborCostData]![FileNamePart] & ".pdf", acExportQualityPrint

End Sub


I am getting run time error 2465: MS Access can't find the field '|1' referred to in your expression.

Seems I am having trouble making the reference back to the query field as well as the quotes around the sting components.


Any suggestions please.

thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:53
Joined
Oct 29, 2018
Messages
21,358
Hi. Try using DLookup() to get the value from the field in the table.
 

Binworkin

New member
Local time
Today, 09:53
Joined
Jun 6, 2020
Messages
9
Hi. Try using DLookup() to get the value from the field in the table.

Thanks, ended up with:
Code:
Private Sub Command6_Click()

Dim FN As String

FN = DLookup("FileNamePart", "qryLaborCostData")

DoCmd.OutputTo acOutputReport, "Task Detail", acFormatPDF, "C:\Users\SH\Desktop\CC\CC Reports\WSP\Production\" & FN & " Task Detail.pdf", acExportQualityPrint

End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:53
Joined
Oct 29, 2018
Messages
21,358
Thanks, ended up with:
Code:
Private Sub Command6_Click()

Dim FN As String

FN = DLookup("FileNamePart", "qryLaborCostData")

DoCmd.OutputTo acOutputReport, "Task Detail", acFormatPDF, "C:\Users\SH\Desktop\CC\CC Reports\WSP\Production\" & FN & " Task Detail.pdf", acExportQualityPrint

End Sub
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom