0

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.

6
Contributors
5
Replies
45
Views
6 Years
Discussion Span
Last Post by princenathan
1

Hi,

To create a numeric textbox, look here.

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

Votes + Comments
agree
1

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.

0

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! :)

0
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 by Ezzaral: Added code tags.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.