-
Ok I have it set that only numbers will work in the text box using the code
If keyascii < 48 or keyascii > 57 then
keyascii = 0
Beep
End if
That works fine, however I want them to be able to use the "Backspace", how can I do that while still having this code or a code that prevents All those keyascii's listed, except the backspace.
-
Try this.
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
'If the Key is not Backspace then
If Not KeyAscii = 8 Then
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Beep
End If
End If
End Sub
-
Nope
Thats what i thought, and had....but doesn't work for some reason...weird, huh?
-
how about this
If KeyAscii < 48 Or KeyAscii > 7 and keyascii < 9 then KeyAscii = 0
Beep
End If
what do you think about that megatron?
-
Strange..See if this works. I've changed 8 to vbKeyBack which is exactly the same except this is a consant.
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
'If the Key is not Backspace then
If Not KeyAscii = vbKeyBack Then
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Beep
End If
End If
End Sub
-
Weird
I don't get y that worked and the 8 didnt if it means the same...... Maybe I have code somewhere else defining 8, since im working a lot with numbers....Thanks!