Hello all,

I would like to make the Tab movement can also pressing the "Enter" Key. I have google and found the code which possible to used. But I found its not running fine with me. When I press "Enter" key,it runs fine for the tab movement.
But if I put something into my textbox,it only allowed me to put 1 character and it will move next. Anyone can help me solve this? Because the Textbox 2 can able to put in any kind of numbers. But after add in the code that allowed "Enter" key move the Tabindex,it will move to the next tab index after I lick 1 character.

Please help me to check is that I use this code wrongly?

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress

        If Keys.Enter Then
            SendKeys.Send("{TAB}")
            Exit Sub
        End If

        Select Case e.KeyChar
            Case "0" To "9"
            Case Microsoft.VisualBasic.ChrW(8) 'backspace
                'Case Microsoft.VisualBasic.ChrW(46) 'dot (.)
                '    If InStr(TextBox2.Text, ".") > 0 Then
                '        e.Handled = True
                '    End If

            Case Else
                e.Handled = True
        End Select

    End Sub

Thanks you all so much for reading. Anyone can give me some suggestion how should I do to make the "Enter" key press work as tab?
Regards
Drex

If you only allow numbers to be entered into your textbox
Try this:

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress

        If e.KeyChar=Chr(Keys.Enter) Then
            If Not IsNumeric(Textbox2.Text) Then
                MsgBox ("Invalid Number Format")
                Me.Textbox2.Focus
                Me.Textbox2.SelectAll
                Exit Sub
              Else
              'do something here
             End If
        End If

    End Sub

So the concept is the Textbox2 only accept numeric entry. If you want to enter an Alphanumeric characters then remove "If Not IsNumeric bla bla bla..

Declare Function As Public Function -> 
Public Sub ValChar(ByVal s1 As TextBox)
        If Not s1.Text = "" Then
            Dim i As Integer
            Dim c As String
            For i = 1 To Len(s1.Text)
                c = Mid(s1.Text, i, 1)
                If Not (c = "." Or c = "0" Or c = "1" Or c = "2" Or c = "3" _Or c = "4" Or c = "5" Or c = "6" Or c = "7" Or c = "8" Or c = "9") _Then
                    s1.Text = Mid(s1.Text, 1, i - 1) + Mid(s1.Text, i + 1, Len _(s1.Text))
                    s1.Select(Len(s1.Text), 1)
                    Exit Sub
                End If
            Next
        End If
    End Sub 
After That Call This Function On TextChanged  Event
E.g.-> Valchar(textbox1)
this allow only numric and decimal value

Edited 7 Years Ago by __avd: Add [code] tags. Encase your code in: [code] and [/code] tags.

This article has been dead for over six months. Start a new discussion instead.