Is there a function that validates that the user has typed letters and not numbers? I have an input box and i need that the user types only numbers.
Printable View
Is there a function that validates that the user has typed letters and not numbers? I have an input box and i need that the user types only numbers.
This code will help you if it's just a plain text box.
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
Don't know how to get it right if it's an InputBox function you are talking about here...
D
If KeyAscii > 48 And KeyAscii < 57 Then
KeyAscii = 0
End If
Inverted...
D
If your using a text box then then checking the keyascii will work fine. If your using an inputbox, then you will need to do something like this
TerryCode:Dim strNumber as string
do until IsNumeric(strNumber) = True
strNumber = InputBox("Enter A Number")
'To Display A Message
If Not IsNumeric(strNumber) Then msgbox("That is not a number")
loop
'Do Something with the number