0

I'd like to print to .pdf out all records of a query, using a report. I have more than 1k records, and would like to save each record as a .pdf. I have concatenated the field "filename" within the query, with the intent to save the report using the "filename" field. The end result would be to click a button "print?" and the database would print to .pdf each record and save the file based on the "filename" field.

I know very little about VBA, and am working through a macro. Macro for Printing Training Checklist report

So, I'm printing a [Report].
The report name is "R Training Checklist".
The variable filename is "filename"

The end result would be a .pdf file saved with the data entered into field "filename" at the identified location.

If I use Output File "C:\Users\mabanes\Creative Cloud Files\Training Checklists\test2.pdf" ...I have no problems. But, I don't want 1k records names "test2.pdf" where I have to go and individual rename each record.

It seems I have something wrong in the expression, but can't seem to figure it out. "C:\Users\mabanes\Creative Cloud Files\Training Checklists\" & Reports![R Training Checklist].[Filename] & ".pdf"

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

1 Answers1

0
Private Sub Create_PDF_Report()

Dim myPath As String
Dim strReportName As String

DoCmd.OpenQuery "QUERYNAME", acViewPreview

myPath = "C:\Users\mabanes\Creative Cloud Files\Training Checklists\"
strReportName = Report_Name.[Whatever you want here] + "etc." + ".pdf"

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

End Sub

Should work for you with a bit of configuring to match your desired filename/path.

Opzen
  • 1
  • So, I get a Compile Error. Private Sub Command29_Click() Dim myPath As String Dim strReportName As String DoCmd.OpenQuery "Q Tasks Assigned", acViewPreview myPath = "C:\Users\mabanes\Creative Cloud Files\Training Checklists\" strReportName = Report_R Training Checklist.[Filename] + ".pdf" DoCmd.OutputTo acOutputReport, "", acFormatPDF, myPath + strReportName, True DoCmd.Close acReport, "Reports" End Sub – Mike Banes Jul 06 '16 at 22:20
  • sorry that looks funky... the like giving me problems is the strReportName = line... – Mike Banes Jul 06 '16 at 22:32