Input box cancel code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • snehadulur
    New Member
    • Aug 2009
    • 3

    Input box cancel code

    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
  • Megalog
    Recognized Expert Contributor
    • Sep 2007
    • 378

    #2
    Here's a quick fix, since you said it was urgent.

    Add this to line 4:

    Code:
    Dim vInput As Variant
    Replace line 20 with:

    Code:
    vInput = InputBox(Msg, "Credit Card Payment", 0)
    
    If vInput = "" Then
        Exit Sub
    Else
        Payment = CCur(vInput)
    End If

    Comment

    • Megalog
      Recognized Expert Contributor
      • Sep 2007
      • 378

      #3
      or you can replace line 20 with this:

      Code:
      If IsNumeric(vInput) Then
          Payment = CCur(vInput)
      ElseIf vInput <> "" Then
          MsgBox "Please enter numeric data only.", vbInformation, "Input Type Mismatch"
          Exit Sub
      Else
          Exit Sub
      End If
      Unlike the first example I gave, this will test the input type in two ways.. so if someone types in "Yo wassup" in the text box it wont give you an error when it tries to convert to currency.

      Comment

      • snehadulur
        New Member
        • Aug 2009
        • 3

        #4
        Thanks a lot for the reply, It works perfect now

        Comment

        • Megalog
          Recognized Expert Contributor
          • Sep 2007
          • 378

          #5
          Glad it works out for you, sorry it took 5 days to get a reply to you..
          Welcome to Bytes!

          Comment

          • snehadulur
            New Member
            • Aug 2009
            • 3

            #6
            :) :) I am going to come up with lots of more doubts in the near future, will keep you posted, thanks a tonne!

            Comment

            Working...