Try this:
Code:
Private Sub cmdPrint_Click()
On Error GoTo Error_Handler
Dim i as Integer
If Me.BeginDate = "" Or IsNull(Me.BeginDate) Then
MsgBox "Please Enter a Ship Date", vbOKOnly, "Incomplete Data"
Me.BeginDate.SetFocus
Exit Sub
End If
If Me.cboDriver = "" Or IsNull(Me.cboDriver) Then
MsgBox "You must select a Driver...", vbOKOnly, "Incomplete Data"
Me.cboDriver.SetFocus
Exit Sub
End If
If DCount("*", "qryCheckForInvoicesToPrint") = 0 Then
MsgBox "There are no invoices to print that have not already been printed or there are not confirmed invoices for this driver.", vbOKOnly + vbCritical + vbDefaultButton4, "Attention!"
Exit Sub
End If
If DCount("*", "qryCheckForUnconfirmedOrders") > 0 Then
MsgBox "There are unconfirmed invoices for this day/driver. Please confirm all invoices for this day/driver before printing.", vbOKOnly + vbCritical + vbDefaultButton4, "Attention!"
Exit Sub
End If
If vbYes = MsgBox("Are you sure you want to send two copies of each confirmed but unprinted invoice directly to the printer?", vbYesNo + vbQuestion + vbDefaultButton2, "Question?") Then
DoCmd.SetWarnings False
Do Until i=2
DoCmd.OpenReport "rptSalesInvoicesByDriver", acViewPreview
DoCmd.PrintOut , , , , 1
i =i + 1
Next
DoCmd.OpenQuery "qryUpdateSalesInvoicesByDriverInvoicePrinted" , acViewNormal, acEdit
If IsFormLoaded("frmReport_SalesInvoicesByDriver") Then
DoCmd.Close acForm, "frmReport_SalesInvoicesByDriver"
End If
DoCmd.SetWarnings True
End If
DoCmd.Close acReport, "rptSalesInvoicesByDriver"
DoCmd.Close
Exit_Procedure:
On Error Resume Next
DoCmd.Hourglass False
' Me.cmdCancel.Enabled = True
Exit Sub
Error_Handler:
MsgBox "An error has occurred in this application." & Err & ", " & Error & vbCrLf & vbCrLf & _
"Please contact your technical support person and report the problem.", vbExclamation, "Error!"
ErrorLog Me.NAME & "_PrintDriverInvoices", Err, Error
' Put the focus back in the database window
DoCmd.SelectObject acTable, "ErrorLog", True
Resume Exit_Procedure
End Sub