When a user hit enter key to go to UnitCost field, price is selected to let user change default price it if he want.IF he press enter he moves to next field without changing it.
Problem is, if price is highlighted e.g 0.010 and user tries to enter .10 it doed not accept the decimal in the beginning. However 0.10 is accepted. The only case a decimal is allowed to enter as first position, is when user clears the existing entry.
I want to allow decimal at first position without clearing.
Please help it is urgent.
Here is my code
- Private Sub txtUnitCost_GotFocus()
-
txtUnitCost.SelStart = 0
-
txtUnitCost.SelLength = Len(txtUnitCost)
-
End Sub
- Private Sub txtUnitCost_KeyPress(KeyAscii As Integer)
-
-
'Validation check
-
' Allows only numeric enteries in the code field discard other characters
-
-
Select Case KeyAscii
-
-
Case Asc(0) To Asc(9)
-
Case Str("8")
-
Case 46
-
Dim position1 As Integer
-
position1 = InStr(txtUnitCost.Text, ".")
-
If position1 <> 0 And KeyAscii = 46 Then
-
KeyAscii = 0
-
position1 = 0
-
End If
-
Case Else
-
KeyAscii = 0
-
End Select
-
-
End Sub
Thanks