how do i force a integer to a textbox?


Posted by karin on July 16, 2001 11:49 AM

i have a text box that i want the user
to be able to enter only integers and not letters or any other kind of data how?



Posted by Dax on July 16, 2001 1:05 PM

You could use some code like this. Double click on the textbox and paste this:-

Private Sub TextBox1_Change()
If Len(TextBox1.Text) < 1 Then Exit Sub

If Asc(Right(TextBox1.Text, 1)) < 48 Or _
Asc(Right(TextBox1.Text, 1)) > 57 Then
TextBox1.Text = Left(TextBox1.Text, Len(TextBox1.Text) - 1)
End If
End Sub

Should do what you want,

regards,
Dax.