textboxes

boxxcar

New Member
Joined
Apr 16, 2020
Messages
20
Platform
  1. Windows
How can I set userform textbox tab order with code when user clicks command button on userform? I have one userform with four command buttons and 3 frames. Depending on the button pushed, the code turns on the appropriate textboxes. I cannot figure out how with the code to set the desired tabindex sequence for the textboxes that have been turned on.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
How can I set userform textbox tab order with code when user clicks command button on userform? I have one userform with four command buttons and 3 frames. Depending on the button pushed, the code turns on the appropriate textboxes. I cannot figure out how with the code to set the desired tabindex sequence for the textboxes that have been turned on.
Any time your using code it's best to show us your code.
Not sure what turns on means.
 
Upvote 0
VBA Code:
   If EE = "Y" Then 'Edit existing Ebay item
                        'or Sold item record
         Worksheets("Ebay Inventory").Activate

        'Turn off Controls not needed
        frmSalesEbay.CommandButton6.Visible = False
        frmSalesEbay.CommandButton7.Visible = False
        frmSalesEbay.CommandButton9.Visible = False
        frmSalesEbay.CommandButton12.Visible = False
        frmSalesEbay.CommandButton13.Visible = False
        frmSalesEbay.CommandButton14.Visible = False
        frmSalesEbay.CommandButton16.Visible = False

        'Turn on Controls needed
        frmSalesEbay.Frame1.Visible = True
        frmSalesEbay.Frame3.Visible = True
        frmSalesEbay.Frame4.Visible = True
        frmSalesEbay.CommandButton11.Visible = True
        frmSalesEbay.CommandButton10.Visible = True
        frmSalesEbay.CommandButton15.Visible = True

        'Turn off textboxes, labels and checkboxes
        For x = 1 To 31
            If x = 1 Or x = 3 Or x > 4 And x < 28 Or x = 27 Then
                With frmSalesEbay.Controls("TextBox" & x)
                    .Visible = False
                    .Enabled = False
                    .TabStop = False
                End With
                With frmSalesEbay.Controls("Label" & x)
                    .Visible = False
                    .Enabled = False
                End With
            End If
            With frmSalesEbay.Controls("CheckBox4")
                .Visible = False
                .Enabled = False
                .TabStop = False
            End With
            With frmSalesEbay.Controls("CheckBox5")
                .Visible = False
                .Enabled = False
                .TabStop = False
            End With
         Next x
        
        'Turn on needed text boxes
        For x = 1 To 30
            If x = 1 Or x = 3 Or x > 4 And x < 20 Or x = 26 Or x = 30 Then
                With frmSalesEbay.Controls("TextBox" & x)
                    .Visible = True
                    .Enabled = True
                    .TabStop = True
                    If x = 1 Then
                        .TabIndex = 4
                    ElseIf x = 3 Then
                        .TabIndex = 5
                    ElseIf x = 5 Then
                        .TabIndex = 3
                        
                        etc...
 
Upvote 0
Your original post said:
Depending on the button pushed, the code turns on the appropriate textboxes

The code you showed involved a lot more then just turning on Textboxes.
So I'm not able to understand all this code.
 
Upvote 0
With the code snippet below, I am trying to step through the set of textboxes that I want to make visible, enabled, and set the tabstop number of. After the code runs, the userform is activated. When the macro runs, I test by using the Tab key expecting the cursor to move to the form textboxes in the order set by this code. The actual order in which the cursor moves around is not the order I have attempted to dictate. The order appears random.
VBA Code:
For x = 1 To 30
            If x = 1 Or x = 3 Or x > 4 And x < 20 Or x = 26 Or x = 30 Then
                With frmSalesEbay.Controls("TextBox" & x)
                    .Visible = True
                    .Enabled = True
                    .TabStop = True
                    If x = 1 Then
                        .TabIndex = 4
                    Elseif x = 2, etc.
                    End If
                End With
          End If
Next x
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,148
Members
448,552
Latest member
WORKINGWITHNOLEADER

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top