467,122 Members | 1,302 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,122 developers. It's quick & easy.

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!



Expand|Select|Wrap|Line Numbers
  1. Private Sub PRINT_Click()
  2.     On Error Resume Next
  3.     ' CopyNumber is global
  4.     Dim NumCopies As Integer, ReportDest As Integer, Msg As String, Payment As Currency, Response As String
  5.  
  6.     'Hide the Invoice Print Dialog
  7.     Forms![yInvoice Print Dialog].Visible = False
  8.     ' Destination is Print Preview
  9.     If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Type of Output] = 1 Then
  10.         ReportDest = A_PREVIEW
  11.       Else      ' Destination is printer
  12.         ReportDest = A_NORMAL
  13.     End If
  14.     NumCopies = Forms![yInvoice Print Dialog]![TabSubfrm].Form![Number Copies].Value
  15.     PrintMessages = Forms![yInvoice Print Dialog]![TabSubfrm].Form![Print Messages].Value
  16.     PrintPayments = Forms![yInvoice Print Dialog]![TabSubfrm].Form![Print Payments].Value
  17.     ' Determine Print Criteria selected
  18.  
  19.     Msg = "How much is being paid by" & vbCrLf & "Credit Card on this Invoice?"
  20.     Payment = InputBox(Msg, "Credit Card Payment", 0)
  21.  
  22.     Select Case Forms![yInvoice Print Dialog]![TabSubfrm].Form![Type of Print]
  23.         Case 1    ' Current Record
  24.             ' Print Standard Invoice
  25.             If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Invoice] = -1 Then
  26.                 For CopyNumber = 1 To (NumCopies - 1)
  27.                     If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then
  28.                         DoCmd.OpenReport "Invoice -Separated", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]"
  29.                     Else
  30.                         DoCmd.OpenReport "Invoice", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]", , Payment
  31.                     End If
  32.                 Next CopyNumber
  33.                         DoCmd.OpenReport "Invoice-Unsigned", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]", , Payment
  34.  
  35.             End If
  36.             ' Print Pro Forma Invoice
  37.             If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Pro Forma Invoice] = -1 Then
  38.                 For CopyNumber = 1 To NumCopies
  39.                     If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then
  40.                         DoCmd.OpenReport "Invoice -Separated", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]"
  41.                     Else
  42.                         DoCmd.OpenReport "Invoice-ProForma Title", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]", , Payment
  43.                     End If
  44.                 Next CopyNumber
  45.             End If
  46.             ' Print Packing List
  47.             If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Packing List] = -1 Then
  48.                 For CopyNumber = 1 To NumCopies
  49.                         DoCmd.OpenReport "Packing List", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]"
  50.                 Next CopyNumber
  51.             End If
  52.             ' Print Commercial Invoice one copy only
  53.             If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Commercial Invoice] = -1 Then
  54.             DoCmd.OpenReport "Invoice-Customs", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]", , Payment
  55.             End If
  56.         Case 2      ' Date Range
  57.             ' Print Standard Invoice
  58.             If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Invoice] = -1 Then
  59.                 For CopyNumber = 1 To NumCopies
  60.                     If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then
  61.                         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])"
  62.                     Else
  63.                         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])"
  64.                     End If
  65.                 Next CopyNumber
  66.             End If
  67.             ' Print Simple Invoice
  68.             'If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Simple Invoice] = -1 Then
  69.             '    For CopyNumber = 1 To NumCopies
  70.             '        If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then
  71.             '            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])"
  72.             '        Else
  73.             '            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])"
  74.             '        End If
  75.             '    Next CopyNumber
  76.             'End If
  77.             ' Print Preprinted Form
  78.             If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Preprinted Form] = -1 Then
  79.                 For CopyNumber = 1 To NumCopies
  80.                     If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then
  81.                         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])"
  82.                     Else
  83.                         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])"
  84.                     End If
  85.                 Next CopyNumber
  86.             End If
  87.         Case 3      ' Customer Number
  88.             ' Print Standard Invoice
  89.             If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Invoice] = -1 Then
  90.                 For CopyNumber = 1 To NumCopies
  91.                     If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then
  92.                         DoCmd.OpenReport "Invoice -Separated", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Sold to Customer]=[Forms]![yInvoice Print Dialog]![TabsubFrm].Form![Customer Number])"
  93.                     Else
  94.                         DoCmd.OpenReport "Invoice", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Sold to Customer]=[Forms]![yInvoice Print Dialog]![TabsubFrm].Form![Customer Number])"
  95.                     End If
  96.                 Next CopyNumber
  97.             End If
  98.             ' Print Pro Forma Invoice
  99.             If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Pro Forma Invoice] = -1 Then
  100.                 For CopyNumber = 1 To NumCopies
  101.                     If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then
  102.                         DoCmd.OpenReport "Invoice -Separated", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]"
  103.                     Else
  104.                         DoCmd.OpenReport "Invoice-ProForma Title", ReportDest, , "[Invoice]![Invoice Number]=[Forms]![Invoice]![Invoice Number]", , Payment
  105.                     End If
  106.                 Next CopyNumber
  107.             End If
  108.             ' Print Preprinted Form
  109.             If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Preprinted Form] = -1 Then
  110.                 For CopyNumber = 1 To NumCopies
  111.                     If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Separate Shipments] Then
  112.                         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])"
  113.                     Else
  114.                         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])"
  115.                     End If
  116.                 Next CopyNumber
  117.             End If
  118.             ' Print Mailing Labels
  119.             If Forms![yInvoice Print Dialog]![TabSubfrm].Form![Commercial Invoice] = -1 Then
  120.                         DoCmd.OpenReport "Invoice-Customs", ReportDest, , "([Invoice Type] = 'F' OR [Invoice Type] = 'I') AND ([Sold to Customer]=[Forms]![yInvoice Print Dialog]![TabsubFrm].Form![Customer Number])"
  121.             End If
  122.     End Select
  123. '    DoCmd.Close A_FORM, "yInvoice Print Dialog"
  124.  
  125. End Sub
Aug 13 '09 #1
  • viewed: 4954
Share:
5 Replies
Megalog
Expert 256MB
Here's a quick fix, since you said it was urgent.

Add this to line 4:

Expand|Select|Wrap|Line Numbers
  1. Dim vInput As Variant
Replace line 20 with:

Expand|Select|Wrap|Line Numbers
  1. vInput = InputBox(Msg, "Credit Card Payment", 0)
  2.  
  3. If vInput = "" Then
  4.     Exit Sub
  5. Else
  6.     Payment = CCur(vInput)
  7. End If
Aug 18 '09 #2
Megalog
Expert 256MB
or you can replace line 20 with this:

Expand|Select|Wrap|Line Numbers
  1. If IsNumeric(vInput) Then
  2.     Payment = CCur(vInput)
  3. ElseIf vInput <> "" Then
  4.     MsgBox "Please enter numeric data only.", vbInformation, "Input Type Mismatch"
  5.     Exit Sub
  6. Else
  7.     Exit Sub
  8. 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.
Aug 18 '09 #3
Thanks a lot for the reply, It works perfect now
Aug 18 '09 #4
Megalog
Expert 256MB
Glad it works out for you, sorry it took 5 days to get a reply to you..
Welcome to Bytes!
Aug 18 '09 #5
:) :) I am going to come up with lots of more doubts in the near future, will keep you posted, thanks a tonne!
Aug 18 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Dalan | last post: by
2 posts views Thread by Mark Lees | last post: by
3 posts views Thread by BerkshireGuy | last post: by
1 post views Thread by Louis Cypher | last post: by
4 posts views Thread by Jimmy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.