Userform textbox's tab sequence

  • My form allows a user to add a new record to the existing records on a worksheet or to edit an existing record present on one of the worksheets. Several of the columns across the sheets are named the same, some are not. I created the one form to present to the user with a command button for each of the sheets. Based on user's button push, I make visible the appropriate textboxes. I want to have the user use the Tab key to move through the textboxes in a specific order. I know how to set the TabStop = True. I know to enter a number for the TabIndex for the sequence across the textboxes. Therefore I need a make visible a different set of textboxes for the user's input and need to change the TabIndex of those fields to match the specific order I want. I have tried several ways but am not yet able to succeed. The results of my efforts seem to create a random tab sequence rather than the one I want. My current hypothesis is I may have to reset the TabStop and TabIndex for every textbox after the user selects a command button. BetaVersionTest.xlsmBetaVersionTest.xlsm. Help, suggestions, will be appreciated.

  • I am following a suggestion to start over with my form and make it multipage.

    On page one the TabIndex settings work and the cursor tabs through the textboxes in the desired order. On page 2 I have two CommandButtons and 20 textboxes. I have set the TabIndex numbers to tab from textbox1 to commandbutton2, to textbox49, to commandbutton11, to textbox50 through textbox67.

    However, the cursor tabs from from textbox1 to commandbutton2, FROM COMMANDBUTTON2 TO TEXTBOX 50, skipping textbox49 and commandbutton11. I have tried to intercept the tab key press on commandbutton 2 with the following code to force the cursor to move to textbox49.

    1. Private Sub CommandButton2__KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    2. If KeyCode = vbKeyTab Then
    3. Me.textBox49.Activate
    4. End If
    5. End Sub

    However, when I step through the code, this Sub is not accessed and the cursor does not go to textbox49. If I move the cursor to textbox49, then click Tab, the cursor moves to textbox50. If I move the cursor to commandbutton11, then click Tab, the cursor moves to textbox50.

    I will happily attach code if that will be helpful.

    Suggestions will be appreciated.

  • Welcome to the Forum. Please read the Forum Rules to understand how the Forum works and why I have added Code Tags to your post

    All VBA code posted in the forum must be wrapped in code tags, which you omitted, including single-line code snippets.Be sure to use them in future posts.

    How to use code tags

    Note: no apostrophe in the tags, just used for demonstration here.


    your code goes between these tags


    Or, just highlight all of the code and press the <> in the post menu above button to add the code tags.