I've an Access app generating many reports, I made a command button to print some reports by one click.
The problem is: I'm using Cancel = True if a report has no data so, the printing process terminated & not complete the rest of reports.
Any advice?
Below is a sample code to create reports as pdf & save it on a folder
Private Sub Savetopdf_Click()
Dim ReportPath As String
Dim CompanyLogo As String
Dim MyWhere As String
Dim ReportOutput As String
Dim ReportName As String
ReportPath = DLookup("AttachentsPath", "emailElements")
ReportName = "Report1"
MyWhere = "[Type] IN ('Type1','Type3','Type4','Type6') and [Company] IN ('Company1', 'Company2') and [Status] In ('Active')"
CompanyLogo = "'Company1','Company2'"
ReportOutput = "Report1 Comp1&Comp2"
DoCmd.OpenReport ReportName, acViewPreview, , MyWhere, acHidden, CompanyLogo
DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF, ReportPath & ReportOutput & ".pdf"
DoCmd.Close acReport, ReportName
MyWhere = "[Type] IN ('Type1','Type3','Type4','Type6') and [Company] IN ('Company3') and [Status] In ('Active')"
CompanyLogo = "'Company3'"
ReportOutput = "Report1 Comp3"
DoCmd.OpenReport ReportName, acViewPreview, , MyWhere, acHidden, CompanyLogo & "|"
DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF, ReportPath & ReportOutput & ".pdf"
DoCmd.Close acReport, ReportName
ReportName = "Report2"
MyWhere = "[Type] IN ('Type1','Type3','Type4','Type6') and [Company] IN ('Company1', 'Company2') and [Status] In ('Active')"
CompanyLogo = "'Company1','Company2'"
ReportOutput = "Report2 Comp1&Comp2"
DoCmd.OpenReport ReportName, acViewPreview, , MyWhere, acHidden, CompanyLogo & "|"
DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF, ReportPath & ReportOutput & ".pdf"
DoCmd.Close acReport, ReportName
MyWhere = "[Type] IN ('Type1','Type3','Type4','Type6') and [Company] IN ('Company3') and [Status] In ('Active')"
CompanyLogo = "'Company3'"
ReportOutput = "Report2 Comp3"
DoCmd.OpenReport ReportName, acViewPreview, , MyWhere, acHidden, CompanyLogo & "|"
DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF, ReportPath & ReportOutput & ".pdf"
DoCmd.Close acReport, ReportName
End Sub
You are right @june7 I used Dlookup to the report based query with the criteria.