Auto Tab to next Textbox

Posted on 2000-01-29
Medium Priority
Last Modified: 2011-04-14
I am creating 3 textboxes so a user can type in a social security number (SSN).  I have set the MaxLength to the 1st textbox to 3 (for the first 3 digits of the SSN).  How can I make the cursor automatically tab to the second box once the MaxLength has been reached? (For example: I want it to perform exactly like entering an Installation key of any product)
Question by:ahelgeson

Accepted Solution

zachar earned 400 total points
ID: 2418581
Use the following code on the 1st text box 'Change' event:

If Len(TextBox1.text)=3 then TextBox2.SetFocus

or better, if the max lenth will be changed in the future:

If Len(TextBox1.text)=TextBox1.MaxLenth  then TextBox2.SetFocus

Good luck.
LVL 12

Expert Comment

ID: 2418603
Quite easy:

Build a new standard VB project,
place 3 textboxen on the form (text1-3) and set each maxlength to 3 and clear the text property.
Then paste this code:

Private Sub Text1_Change()
    If Len(Text1.Text) = Text1.MaxLength Then SendKeys "{TAB}"
End Sub

Private Sub Text2_Change()
    If Len(Text2.Text) = Text1.MaxLength Then SendKeys "{TAB}"
End Sub

Private Sub Text3_Change()
    If Len(Text3.Text) = Text1.MaxLength Then SendKeys "{TAB}"
End Sub

This way you can make it an indepentant TAB, you don't have to know design time which text box is next.

grtx, RoverM

Expert Comment

by:Seven price
ID: 20567759
question on this where do you declare the SendKeys

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question