4
Contributors
7
Replies
30
Views
4 Years
Discussion Span
Last Post by AndreRet
0

if the inputted character is letter then
use the statement

KeyAscii=0

you have to write that code on the key press event of the text box

now i hope that you can handle the issue with ASCII VALUES of letters

if you think letters as alphabets then ascii value range is 65 to 90 and 97 to 122

Edited by rishif2

0
If (KeyAscii <= vbKey9 And KeyAscii >= vbKey0 Or KeyAscii = vbBack) Then
Else
KeyAscii = 0
End If

found this code on youtube but it doesnt on me i got a debug...
can you tell me whats wrong with that code...i put it in the keypress on the textbox...

0

try this

If Not (KeyAscii <= vbKey9 And KeyAscii >= vbKey0 Or KeyAscii = vbKeyBack) Then
KeyAscii = 0
End If

hope this helps you to solve the issue

0

There are 2 ways to do this -

  1. When your textbox looses focus, trap the error...

    If Not IsNumeric(Text1.Text) Then

    MsgBox "Numeric input only!", vbCritical, "Invalid Input"

    Text1.Text = ""

    End If

OR, you can just delete the letter that was typed so it only accepts numbers...

Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Text1.Text) Then 
SendKeys {Backspace}
End If
End Sub

''Note, you HAVE to reference Microsoft Scripting Library in your project...
''This will delete any letters or symbols except for numeric values. The ".," is allowed...
0

Wow thanks for the help everyone i really learned a lot..
i tried all your answer and it really works... thanks again everyone!!!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.