J
Joan
Hi,
The code that I have written to loop through Invoice records and print them
out one by one is not working as it should. My code is only printing the
first Invoice record in the range and not the others. Below is my code.
Can someone tell me where my problem is?
Private Sub cmdPrint_Click()
'On Error GoTo Err_cmdPrint_Click
Dim DB As Database
Dim rstInvoices As DAO.Recordset
Dim InvoiceCriteria As String
............
Case 2 'Print Invoice Number range.
'Print range of invoices' Invoice Statement
If Forms![frmPrintReportsDialog2]![ckInvoice] = -1 Then
Report = "rptInvoiceStatement"
Set DB = CurrentDb
Set rstInvoices = DB.OpenRecordset("SELECT * FROM Invoices
WHERE (Invoices.[Invoice Number] Between " & Forms!
frmPrintReportsDialog2!FromInvoice & " And " &
Forms!frmPrintReportsDialog2!ToInvoice & ") And (Invoices.Type = 'INV')",
dbOpenDynaset)
Do While Not rstInvoices.EOF
InvoiceCriteria = rstInvoices("[Invoice Number]")
rstInvoices.Edit
If ReportDest = acPreview Then
DoCmd.OpenReport Report, ReportDest, ,
"[Invoices].[Invoice Number] = " & InvoiceCriteria
Else 'if choose to print, open report in acPreview,
otherwise PrintOut prints (ISCopies) copies of dialog form and not report.
ISCopies = Me!txtISCopies
DoCmd.OpenReport Report, acViewPreview, ,
"[Invoices].[Invoice Number] =" & InvoiceCriteria
DoCmd.PrintOut , , , , ISCopies
End If
rstInvoices.Update
rstInvoices.MoveNext
Loop
End If
rstInvoices.Close
To move to the next record in the record set, don't I have to first Update
the recordset? Or do I have something out of order? Any help with this
would be appreciated.
Joan
The code that I have written to loop through Invoice records and print them
out one by one is not working as it should. My code is only printing the
first Invoice record in the range and not the others. Below is my code.
Can someone tell me where my problem is?
Private Sub cmdPrint_Click()
'On Error GoTo Err_cmdPrint_Click
Dim DB As Database
Dim rstInvoices As DAO.Recordset
Dim InvoiceCriteria As String
............
Case 2 'Print Invoice Number range.
'Print range of invoices' Invoice Statement
If Forms![frmPrintReportsDialog2]![ckInvoice] = -1 Then
Report = "rptInvoiceStatement"
Set DB = CurrentDb
Set rstInvoices = DB.OpenRecordset("SELECT * FROM Invoices
WHERE (Invoices.[Invoice Number] Between " & Forms!
frmPrintReportsDialog2!FromInvoice & " And " &
Forms!frmPrintReportsDialog2!ToInvoice & ") And (Invoices.Type = 'INV')",
dbOpenDynaset)
Do While Not rstInvoices.EOF
InvoiceCriteria = rstInvoices("[Invoice Number]")
rstInvoices.Edit
If ReportDest = acPreview Then
DoCmd.OpenReport Report, ReportDest, ,
"[Invoices].[Invoice Number] = " & InvoiceCriteria
Else 'if choose to print, open report in acPreview,
otherwise PrintOut prints (ISCopies) copies of dialog form and not report.
ISCopies = Me!txtISCopies
DoCmd.OpenReport Report, acViewPreview, ,
"[Invoices].[Invoice Number] =" & InvoiceCriteria
DoCmd.PrintOut , , , , ISCopies
End If
rstInvoices.Update
rstInvoices.MoveNext
Loop
End If
rstInvoices.Close
To move to the next record in the record set, don't I have to first Update
the recordset? Or do I have something out of order? Any help with this
would be appreciated.
Joan