|
Public Sub DecCheck(Target As String, ByRef KeyStroke As _
Integer) If InStr(Target, ".") And KeyStroke = 46 Then KeyStroke = 0 End If End Sub Public Sub NumCheck(ByRef KeyStroke As Integer) If (KeyStroke < 48 Or KeyStroke > 57) And (KeyStroke _ <> 46 And KeyStroke <> 8) Then KeyStroke = 0 End If End Sub Then invoke the code from your TextBox's KeyPress event: Private Sub txtUnitPrice_KeyPress(KeyAscii As Integer) DecCheck txtUnitPrice, KeyAscii NumCheck KeyAscii End Sub 'One caveat: This code doesn't prevent text characters from being pasted 'in via the clipboard. |