Sorry, I was incorrect on the report formatting. The form frmOrderEntry displays invoices and the report rptInvoices has its filter set to the order currently being displayed, as follows [OrderID]=[Forms]![frmOrderEntry]![OrderID]
I have created a copy of rptInvoices named rptYellows (literally to print copies of each invoice, if required, on yellow paper) which is based on the same query. From a form called frmPrintReports I have written the following code to loop through each invoice and print the yellow copy if appropriate
Code:
Dim stDocName As String
Dim stDailyReport As String
Dim intNumberRecords As Integer
Dim InvoicePaid As Boolean
Dim PrintYellows As Boolean
Dim InvoiceDate As Date
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb()
' Do While Not (rs.EOF)
Set rs = db.OpenRecordset("tblInvoices")
Me.txtCriteria = rs!OrderID
Me.txtCriteria2 = rs!CustomerID
Me.txtCriteria3 = rs!Date
InvoicePaid = DLookup("[Paid]", "tblInvoices", "[OrderId] = Forms!frmPrintReports.txtCriteria")
PrintYellows = DLookup("[PrintYellows]", "tblCustomers", "[CustomerId] = Forms!frmPrintReports.txtCriteria2")
InvoiceDate = DLookup("[Date]", "tblInvoices", "[OrderId] = Forms!frmPrintReports.txtCriteria")
If InvoiceDate >= Me.BeginningDate And InvoiceDate <= Me.EndingDate And InvoicePaid = False And PrintYellows = True Then
stDocName = " rptYellows"
DoCmd.OpenReport stDocName, acPreview, [OrderID] = [Forms]![frmPrintReports]![txtCriteria]
Else
MsgBox "Not printing Invoice # " & Me.txtCriteria, _
vbExclamation, conAppName
End If
' rs.MoveNext
'Loop
rs.Close
Exit Sub
End Select
Exit_cmdPrintAllReports_Click:
Exit Sub
Err_cmdPrintAllReports_Click:
MsgBox Err.Description
Resume Exit_cmdPrintAllReports_Click
End Sub
I am having trouble with the correct syntax for passing the orderID to the report. Should I leave the rptYellows filter blank?
Thanks