Input box cancel code

snehadulur

New member
Local time
Today, 13:54
Joined
Aug 13, 2009
Messages
2
In the input box if we click ok or cancel the invoice prints. By default the credit card info is 0, and most of the cases its 0 even when we want to take a print out i.e., the value is changed.
I tried doing If Payment = "" Then Exit sub,

but it exits the sub if I press ok or cancel since the credit card value is not changed and remains to be 0.

WHat changes can I make so that if ok is clicked the document prints and if cancel is clicks it exits the sub, even if credit card value continues to remain 0. Its very very urgent!



Code:
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 Sub
 
I'm not sure I really understand what you are saying, but if you do

if Payment=>0
'your printing code
end if

then if nothing is entered, it shouldn't print. Is that what you were asking?
 
The default value we have is 0, sometimes when there is no value to be entered the value remains 0. If I click ok it should print, and if I click cancel it should cancel, but it does not cancel instead it still prints.

I want it to cancel on clicking cancel and not print.
 
Since you sometimes want to print with a value of 0, I don't think it is possible to do what you are asking (maybe someone else knows a way, but I don't). Input boxes are pretty limited. I would suggest creating your own custom form that looks like an input box. Then, instead of using an input box in your code, open your custom form. You can attach printing code to the on click event of the ok button on your form, and just make the form close in the on click event of the cancel button.
 

Users who are viewing this thread

Back
Top Bottom