Hey

I want to control a textbox to only allow numbers, backspace and a certain length. Ive tried with the IsNumeric function but I cant seem to get it to work.

Thanks.

Hi,

To create a numeric textbox, look here.

To select a certain length, go to the properties of that textbox and set the Maxlength.

Comments
agree

Just put this code in your keypress event in your textbox

Select Case e.KeyChar
            Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", vbBack
                e.Handled = False
            Case Else
                e.Handled = True
        End Select

if you want to change the input length of textbox just click the properties and then change the MaxLength Value.

Just put this code in your keypress event in your textbox

Select Case e.KeyChar
            Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", vbBack
                e.Handled = False
            Case Else
                e.Handled = True
        End Select

if you want to change the input length of textbox just click the properties and then change the MaxLength Value.

Nice solution!
Thanks so much! :)

If Textbox1.Text = "" Then
            GoTo ex

        Else
            If IsNumeric(Textbox1.Text) Then
                GoTo ex
            Else
                MsgBox("You cannot add alpha characters, please input the Integer or numbers !", vbCritical)
                Textbox1.Text = ""
                searchback()
            End If
        End If
ex:
        Exit Sub

Edited 4 Years Ago by Ezzaral: Added code tags.

This question has already been answered. Start a new discussion instead.