I'm trying to edit the below code to meet a new challenge. Previously, it would print a merchant packing list from one merchant, no problem.
Problem: I'd like to print to one PDF file all merchant packing lists. Does anyone have a sample of this? As I see it, I would have to print one packing list to a PDF, then loop through a record set adding pages to the PDF. Is it possible to add pages to an existing PDF using a module? As you might expect, with each record I'm overwriting the file for each record. Each merchant has their own custom packing list. So it's not like I can create a single report with all merchants then print it. I would be looping through each merchants packing list and adding to the PDF.
Can anyone point me in the right direction? No doubt I could be missing something that would be much easier.
Code:
Public Function PackingLists_CA()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim varReportName As String
Dim varReportFileName As String
Dim varPLModule As String
Dim temp As String
Dim PackListQuery As String
Dim ReportName As String
PackListQuery = "qry_PackingLists_Modules_CA"
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT Distinct [ReportName],[ReportFileName] FROM " & PackListQuery, dbOpenSnapshot)
Do While Not rs.EOF
varReportName = rs("ReportName")
varReportFileName = rs("ReportFileName") & ".pdf"
'acViewPreview = Print Preview, acViewReport = Direct to Printer
DoCmd.OpenReport varReportName, acViewPreview, , "[FileNam]='" & varReportFileName & "'"
DoCmd.OutputTo acOutputReport, "", acFormatPDF, varReportFileNam
DoCmd.Close acReport, varReportName
DoEvents
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Function
thanks!