When you are working with a userform to create a userinterface for data input, sometimes you would like to restrict the users to input numbers only in some of the textbox controls. However, many a times you would find accidently or otherwise, you find text entered into the database. You can use the following code to make sure that anything typed in textbox1 other than numbers 0 – 9 will not be accepted. Thus you can successfully implement to reduce errors in your database.
|
Private Sub TextBox1_KeyPress( _ ByVal KeyAscii As MSForms.ReturnInteger) ‘ This code restricts any text in textbox1 other than ‘ integer 0 – 9 …. Select Case KeyAscii Case Asc(“0″) To Asc(“9″) Case Else KeyAscii = 0 End Select End Sub |