Hello! I have one report I'm trying to run through VBA that will output 500 territories in own PDF (so 500 PDFs when done). Help needed with error saying "Too Few Parameters". Here is what I have for my VBA...any help you can offer is GREATLY appreciated!
Function PrintReports()
Dim sql As String
Dim db As Database
Dim rs As Recordset
sql = "SELECT TERRITORY, CODE, LAST_NAME FROM TERR_CODES"
Set db = CurrentDb
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
Do Until rs.EOF
DoCmd.OpenReport "Q2_Reports", acViewPreview, , "[TERRITORY]='" & rs![TERRITORY] & "'"
DoCmd.OutputTo acOutputReport, "Q2_Reports", "PDFFormat(*.pdf)", "C:\Desktop\PrintFiles\" & rs![TERRITORY] & " - " & rs!
Function PrintReports()
Dim sql As String
Dim db As Database
Dim rs As Recordset
sql = "SELECT TERRITORY, CODE, LAST_NAME FROM TERR_CODES"
Set db = CurrentDb
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
Do Until rs.EOF
DoCmd.OpenReport "Q2_Reports", acViewPreview, , "[TERRITORY]='" & rs![TERRITORY] & "'"
DoCmd.OutputTo acOutputReport, "Q2_Reports", "PDFFormat(*.pdf)", "C:\Desktop\PrintFiles\" & rs![TERRITORY] & " - " & rs!
Code:
& " - " & rs![LAST_NAME] & ".pdf", False
DoCmd.Close acReport, "Q2_Reports"
DoEvents
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
MsgBox ("Reports have been printed.")
End Function