Kris,
Whoops ... I left off a conversion (chr$(KeyAscii) ). Use this instead.
It's a few more keystrokes than the other example (which is also valid
except for the backspace) but it is good programming practice to write your
code so if someone else comes along they can understand the intent. While
this is an overly simple section of code, developing that habit will pay
off. The extra time making code clear can pay off big-time later when
trying to find bugs.
Private Sub Text1_KeyPress( KeyAscii As Integer)
'
' Invalidate keystroke if not a digit, decimal point or backspace.
'
If (Not IsNumeric(chr$( KeyAscii)) And (chr$(KeyAscii) <> "." And
KeyAscii <> vbBack)) Then
KeyAscii = 0
Endif
End Sub
HTH,
-bruce
"Kris M" <ma******@yahoo .com> wrote in message
news:bY******** ************@co mcast.com...
Private Sub Text1_KeyPress( KeyAscii As Integer) If (KeyAscii < 48 Or
KeyAscii > 57) And KeyAscii <> 46 Then KeyAscii = 0 End IfEnd
Sub"J. C. O'Connell" <hi******@gate. net> wrote in message
news:3f******** ******@news.gat e.net...> hi,
I HAVE A TEXT BOX THAT I WANT THE USER TO ENTER A NUMBER IN.
HOW DO I PREVENT RUN TIME ERROR IF THEY ENTER A STRING INSTEAD?
I GUESS I NEED SOME TYPE OF DATA TYPE SENSING COMMAND BUT I
DONT KNOW WHAT IT IS.
jco