The txtAddEditEntryItemDiscount is a textbox. It is set for Currency with two decimal points. (Though I technically don't need the decimal values as they are always zero, but this is a Cash Register Program and I like to have the ".00" on the screen.
I am screening all key inputs so only BACKSPACE KEY, ENTER KEY Or one of the digit keys are accepted, all others are rejected.
I also want the cursor to ONLY be next to the decimal point. So if the BACKSPACE key is pressed, it deletes the last digit entered, if a digit key is entered in that position. I even have a onclick event where if you attempt to move the cursor someplace else, it automatically moves it back to the left of the decimal point.
Here's the issue. When I run this SUB and I enter a digit the text box empties and only the digit that I entered shows up. HOWEVER, if I add a breakpoint and go through each step using F8, when the SUB is done, it displays as I like. For example, when the Form Loads, the Textbox show $0.00. I press the 2 Digit. Without the Breakpoint only the 2 is displayed in the Textbox. When I go through it STEP by STEP, it shows as $2.00. What is going on.
Thanks all for your help.
Ken L
Code:The following are GLOBAL in a separate Module GLOBAL rcdFindItemQty GLOBAL rcdFindItemPrice GLOBAL rcdAddEditEntryItemDiscount GLOBAL rcdFindItemTotal And in the FORM LOAD sub the above values are zeroed out. These variables are needed in another Module which is why they are GLOBAL. Private Sub txtAddEditEntryItemDiscount_KeyDown(KeyCode As Integer, Shift As Integer) ' *********************************** Dim EditedNumberToItemPrice As String Dim EditedItemPrice As Currency Dim EditedItemPriceAsString Dim rcdAddEditEntryItemDiscount As Currency Dim FormattingItemDiscount As Currency Dim TruncatedItemDiscountNumber ' *********************************** If KeyCode = 8 Then ' ******************************* BACKSPACE PRESSED ************************************************************* If Mid(txtAddEditEntryItemDiscount.Text, 2, 1) = 0 Then txtAddEditEntryItemDiscount.Text = 0 Else TruncatedItemDiscountNumber = Left(txtAddEditEntryItemDiscount.Text, (Len(txtAddEditEntryItemDiscount.Text) - 4)) If Right(TruncatedItemDiscountNumber, 1) = "$" Then txtAddEditEntryItemDiscount.Text = 0 Else txtAddEditEntryItemDiscount.Text = Left(txtAddEditEntryItemDiscount.Text, (Len(txtAddEditEntryItemDiscount.Text) - 4)) End If End If ElseIf (KeyCode > 47 And KeyCode < 58) Or (KeyCode > 95 And KeyCode < 106) Then ' ******************************* NUMBER PRESSED **************************************************************** If KeyCode = 48 Or KeyCode = 96 Then '4 EditedNumberToItemPrice = "0" ElseIf KeyCode = 49 Or KeyCode = 97 Then EditedNumberToItemPrice = "1" ElseIf KeyCode = 50 Or KeyCode = 98 Then EditedNumberToItemPrice = "2" ElseIf KeyCode = 51 Or KeyCode = 99 Then EditedNumberToItemPrice = "3" ElseIf KeyCode = 52 Or KeyCode = 100 Then EditedNumberToItemPrice = "4" ElseIf KeyCode = 53 Or KeyCode = 101 Then EditedNumberToItemPrice = "5" ElseIf KeyCode = 54 Or KeyCode = 102 Then EditedNumberToItemPrice = "6" ElseIf KeyCode = 55 Or KeyCode = 103 Then EditedNumberToItemPrice = "7" ElseIf KeyCode = 56 Or KeyCode = 104 Then EditedNumberToItemPrice = "8" ElseIf KeyCode = 57 Or KeyCode = 105 Then EditedNumberToItemPrice = "9" End If ' ******************************* ADDING DIGITS TO AMOUNT *************************************************** If txtAddEditEntryItemDiscount.Value = 0 Then EditedItemPriceAsString = EditedNumberToItemPrice EditedItemPrice = EditedItemPriceAsString txtAddEditEntryItemDiscount.Text = EditedItemPrice txtAddEditEntryItemDiscount.SelStart = (Len(txtAddEditEntryItemDiscount.Text) - 3) Else EditedItemPriceAsString = EditedItemPriceAsString & EditedNumberToItemPrice EditedItemPrice = EditedItemPrice & EditedItemPriceAsString txtAddEditEntryItemDiscount.Value = EditedItemPrice txtAddEditEntryItemDiscount.SelStart = (Len(txtAddEditEntryItemDiscount.Text) - 3) End If ElseIf KeyCode = 13 Then ' ******************************* ENTER KEY PRESSED - DISCOUNT AMOUNT COMPLETE ************************************* KeyCode = vbKeyUp FormattingItemDiscount = txtAddEditEntryItemDiscount.Text FormattingItemDiscount = Format(FormattingItemDiscount, "$ ###.00") txtAddEditEntryItemDiscount.Value = FormattingItemDiscount If txtAddEditEntryItemPrice.Value > 0 Then ' *************************** PRICE ENTERED - CALCULATE TOTAL AMOUNT **************************************** rcdFindItemQty = txtAddEditEntryItemQty.Value rcdFindItemPrice = txtAddEditEntryItemPrice.Value rcdAddEditEntryItemDiscount = txtAddEditEntryItemDiscount.Value rcdFindItemTotal = txtAddEditEntryItemTotal.Value rcdFindItemTotal = rcdFindItemTotal - rcdAddEditEntryItemDiscount ' *************************** txtAddEditEntryItemTotal.Value = rcdFindItemTotal txtAddEditEntryItemTotal.SetFocus txtAddEditEntryItemTotal.SelStart = Len(txtAddEditEntryItemTotal.Value) Else ' *************************** NO AMOUNT ENTERED FOR PRICE - CANNOT CALVULATE TOTAL AMOUNT ******************* MsgBox ("PLEASE ENTER PRICE BEFORE ENTERING DISCOUNT") KeyCode = vbKeyUp txtAddEditEntryItemDiscount.Value = 0 Exit Sub End If End If txtAddEditEntryItemDiscount.SelStart = (Len(txtAddEditEntryItemDiscount.Text) - 3) ' ******************************************************************************************************************* End Sub


An inconsistent result with this Sub
Reply With Quote


