How to code for text box if length of textbox1 is 5 then textbox2 focus()??

In the KeyPress event of the textbox1 text box, check for the text length. When text length is equal to 5 set the focus to textbox2 using Focus() method

I was having the same problem before.

If Textbox1.TextLength = 5 Then
    TextBox2.Focus
End If

There is a easy process. Take a Form and Two Textbox. At first, Set Form's KeyPreview Property to 'True'. Now write the following code.

Public Class Form1

    Private Sub Form1_KeyUp(sender As Object, e As     System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        If Me.ActiveControl Is TextBox1 Then
            If TextBox1.Text.Length >= 5 Then
                TextBox2.Focus()

            End If
        End If
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = ""
        TextBox2.Text = ""
    End Sub
End Class

Same mistake here as in two other threads. By filtering at the form level you affect the bahaviour of all textboxes at the top level of the form.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.