Answer» This is the code I have, the cancel button in the input box when pressed still prints the INVOICE, I have a tried a lot of combinations, any help would be appreciated
Code: [Select]Private Sub PRINT_Click() On Error Resume Next ' CopyNumber is global Dim NumCopies As Integer, ReportDest As Integer, Msg As String, Payment As Currency, Response As String
'Hide the Invoice Print Dialog Forms![yInvoice Print Dialog].Visible = False ' Destination is Print Preview If Forms![yInvoice Print Dialog]![TabSubfrm].Form![TYPE of Output] = 1 Then ReportDest = A_PREVIEW Else ' Destination is printer ReportDest = A_NORMAL End If NumCopies = Forms![yInvoice Print Dialog]![TabSubfrm].Form![Number Copies].Value PrintMessages = Forms![yInvoice Print Dialog]![TabSubfrm].Form![Print Messages].Value PrintPayments = Forms![yInvoice Print Dialog]![TabSubfrm].Form![Print Payments].Value ' Determine Print Criteria selected
Msg = "How much is being paid by" & vbCrLf & "Credit CARD on this Invoice?" Payment = InputBox(Msg, "Credit Card Payment", 0)
Select Case Forms![yInvoice Print Dialog]![TabSubfrm].Form![Type of Print] Case 1 ' Current Record ' Print Standard Invoice If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Invoice] = -1 Then For CopyNumber = 1 To (NumCopies - 1) If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then DoCmd.OpenReport "Invoice -Separated", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]" Else DoCmd.OpenReport "Invoice", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]", , Payment End If Next CopyNumber DoCmd.OpenReport "Invoice-Unsigned", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]", , Payment End If ' Print Pro Forma Invoice If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Pro Forma Invoice] = -1 Then For CopyNumber = 1 To NumCopies If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then DoCmd.OpenReport "Invoice -Separated", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]" Else DoCmd.OpenReport "Invoice-ProForma Title", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]", , Payment End If Next CopyNumber End If ' Print Packing List If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Packing List] = -1 Then For CopyNumber = 1 To NumCopies DoCmd.OpenReport "Packing List", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]" Next CopyNumber End If ' Print Commercial Invoice one copy only If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Commercial Invoice] = -1 Then DoCmd.OpenReport "Invoice-Customs", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]", , Payment End If Case 2 ' Date Range ' Print Standard Invoice If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Invoice] = -1 Then For CopyNumber = 1 To NumCopies If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then DoCmd.OpenReport "Invoice -Separated", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Invoice]![Invoice Date] Between [Forms]![yInvoice Print Dialog]![TabsubFrm].Form![From Date] And [Forms]![yInvoice Print Dialog]![TabsubFrm].Form![To Date])" Else DoCmd.OpenReport "Invoice", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Invoice]![Invoice Date] Between [Forms]![yInvoice Print Dialog]![TabsubFrm].Form![From Date] And [Forms]![yInvoice Print Dialog]![TabsubFrm].Form![To Date])" End If Next CopyNumber End If ' Print Simple Invoice 'If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Simple Invoice] = -1 Then ' For CopyNumber = 1 To NumCopies ' If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then ' DoCmd.OpenReport "Invoice Single LINE -Separated", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Invoice]![Invoice Date] Between [Forms]![yInvoice Print Dialog]![TabsubFrm].Form![From Date] And [Forms]![yInvoice Print Dialog]![TabsubFrm].Form![To Date])" ' Else ' DoCmd.OpenReport "Invoice Single Line", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Invoice]![Invoice Date] Between [Forms]![yInvoice Print Dialog]![TabsubFrm].Form![From Date] And [Forms]![yInvoice Print Dialog]![TabsubFrm].Form![To Date])" ' End If ' Next CopyNumber 'End If ' Print Preprinted Form If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Preprinted Form] = -1 Then For CopyNumber = 1 To NumCopies If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then DoCmd.OpenReport "Invoice Just Data -Separated", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Invoice]![Invoice Date] Between [Forms]![yInvoice Print Dialog]![TabsubFrm].Form![From Date] And [Forms]![yInvoice Print Dialog]![TabsubFrm].Form![To Date])" Else DoCmd.OpenReport "Invoice Just Data", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Invoice]![Invoice Date] Between [Forms]![yInvoice Print Dialog]![TabsubFrm].Form![From Date] And [Forms]![yInvoice Print Dialog]![TabsubFrm].Form![To Date])" End If Next CopyNumber End If Case 3 ' Customer Number ' Print Standard Invoice If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Invoice] = -1 Then For CopyNumber = 1 To NumCopies If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then DoCmd.OpenReport "Invoice -Separated", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Sold to Customer]=[Forms]![yInvoice Print Dialog]![TabsubFrm].Form![Customer Number])" Else DoCmd.OpenReport "Invoice", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Sold to Customer]=[Forms]![yInvoice Print Dialog]![TabsubFrm].Form![Customer Number])" End If Next CopyNumber End If ' Print Pro Forma Invoice If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Pro Forma Invoice] = -1 Then For CopyNumber = 1 To NumCopies If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then DoCmd.OpenReport "Invoice -Separated", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]" Else DoCmd.OpenReport "Invoice-ProForma Title", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]", , Payment End If Next CopyNumber End If ' Print Preprinted Form If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Preprinted Form] = -1 Then For CopyNumber = 1 To NumCopies If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then DoCmd.OpenReport "Invoice Just Data -Separated", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Sold to Customer]=[Forms]![yInvoice Print Dialog]![TabsubFrm].Form![Customer Number])" Else DoCmd.OpenReport "Invoice Just Data", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Sold to Customer]=[Forms]![yInvoice Print Dialog]![TabsubFrm].Form![Customer Number])" End If Next CopyNumber End If ' Print Mailing Labels If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Commercial Invoice] = -1 Then DoCmd.OpenReport "Invoice-Customs", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Sold to Customer]=[Forms]![yInvoice Print Dialog]![TabsubFrm].Form![Customer Number])" End If End Select ' DoCmd.Close A_FORM, "yInvoice Print Dialog"
End Subwhen you press "cancel" inputbox returns an empty string. So check for that after the inputbox:
Code: [Select] Payment = InputBox(Msg, "Credit Card Payment", 0) if payment="" then exit sub
|