the user should enter a digit instead??? what shall i use???

Recommended Answers

All 3 Replies

Try this:

Private Sub Text1_KeyPress(KeyAscii As Integer)

    Select Case KeyAscii
    Case 48 To 57
        ' These are acceptable keystrokes
    Case Else
        ' These are unacceptable, and should be ignored
        KeyAscii = 0
    End Select
    
End Sub

The numbers 48 to 57 are the ascii values of the numbers 0 to 9
more characters can be added.

i.e. 12,48 to 57,65,69 etc

Either single numbers or groups.

Pg

it worked. thanks but when i press the backspace key it prompted me an error msg. why is that so?

Private Sub Text1_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
    Case 48 To 57
        ' These are acceptable keystrokes
    Case 8
        
    Case Else
        ' These are unacceptable, and should be ignored
        KeyAscii = 0
    End Select
    
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.