Home > How-To Library > Controls

How to Prevent the user from entering invalid keys in a text box.

**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * ****************************************************************
Private Sub Text1_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case Is < 32 ' Control keys are OK. Case 48 To 57 ' This is a digit. Case Else ' Reject any other key. KeyAscii = 0 End Select End Sub

If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.