Allow only numbers in a textbox!

By | 2002-06-01

This program won’t allow any other characters in a textbox then numbers and it allows you to use your Backspace key.

Original Author: RayDance

Code

Private Sub text1_KeyPress(KeyAscii As Integer)
  Dim Numbers As Integer
  Dim Msg As String
  
  Numbers = KeyAscii
  
  If ((Numbers < 48 Or Numbers > 57) And Numbers <> 8) Then
   Msg = MsgBox("Only Numbers are aloud in this Textbox", vbCritical, "Error Number")
   KeyAscii = 0
  End If
End Sub

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.