Results 1 to 6 of 6

Thread: Tab Control and Tabbing backwards(Shift+tab)

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    3

    Question Tab Control and Tabbing backwards(Shift+tab)

    Hi,

    Using a SSTab control and I want to switch from Tab1 to Tab0 without using the mouse.

    How can I tel VB to switch from Tab1 to Tab0 if I'm pressing the Shift+Tab keys.

    It's easy done for Tab0 to Tab1 buy putting code in the last controls
    Validate event of tab0:
    VB Code:
    1. Private Sub Text_Validate(Cancel As Boolean)
    2.  
    3.     SSTab1.Tab = 1
    4.  
    5. End Sub

    So now I'm on the first control of Tab1 and I want too Tab backwards. Any ideas will be great

    Thanks
    Darren

  2. #2
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Tab Control and Tabbing backwards(Shift+tab)

    You can try this...

    1st Change the property: Form.KeyPreview = True or do this in Form_Load

    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2.         'Assign actual Tab to Variable
    3.         Dim intActualTab As Integer
    4.         intActualTab = SSTab1.Tab
    5.        
    6.         'Change Down SSTab
    7.         If KeyCode = vbKeyPageDown & vbKeyControl Then
    8.                 'First Tab
    9.                 If SSTab1.Tab > 0 Then
    10.                         SSTab1.Tab = intActualTab - 1
    11.                 End If
    12.         End If
    13.        
    14.         'Change UP SSTab
    15.         If KeyCode = vbKeyPageUp & vbKeyControl Then
    16.                 'Last Tab
    17.                 If SSTab1.Tab < SSTab1.Tabs - 1 Then
    18.                         SSTab1.Tab = intActualTab + 1
    19.                 End If
    20.         End If
    21.  
    22. End Sub
    Many softwares, like Excel, use Ctrl PageUp and Ctrl PageDown to browse trough Tabs...

    I hope this will help you...
    Last edited by DubweiserTM; Sep 20th, 2006 at 10:46 AM. Reason: Change vbKeyControl instead of Ctrldown
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  3. #3
    Hyperactive Member ProphetBeal's Avatar
    Join Date
    Aug 2006
    Location
    New York
    Posts
    424

    Re: Tab Control and Tabbing backwards(Shift+tab)

    I have found that this code below works best.

    VB Code:
    1. Private Sub SSTab1_KeyDown(KeyCode As Integer, Shift As Integer)    
    2.     Select Case KeyCode
    3.         Case 9
    4.             Dim intCounter As Integer
    5.             With SSTab1
    6.                 If Shift = 1 Then
    7.                     intCounter = -1 + .Tab
    8.                 Else
    9.                     intCounter = 1 + .Tab
    10.                 End If
    11.                 Select Case intCounter
    12.                     Case Is < 0
    13.                         .Tab = .Tabs - 1
    14.                     Case Is > .Tabs - 1
    15.                         .Tab = 0
    16.                     Case Else
    17.                         .Tab = intCounter
    18.                 End Select
    19.             End With
    20.     End Select
    21. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    3

    Re: Tab Control and Tabbing backwards(Shift+tab)

    Hi, Thanks DubweiserTM and ProphetBeal,

    Both code works very nice but what I really do I need is:

    Tab0:
    10 text boxes
    txtName1 to txtName10

    Tab1
    2 option buttons 3 text boxes.
    opt1, opt2 txtName11 to txtName13

    I tab from TextBox10 LostFocus or Validate (last control) i put SSTab1.Tab = 1 which will:

    1. Switches to Tab1
    2. Give focus to 1st control on screen which is opt1

    TabIndex property of txtName10 = 9 and TabIndex property of opt1 = 10
    This works a treat.

    But if I'm on opt1 and I press Shift+Tab the cursor sets focus to TxtName10 but the Tab does not switch too Tab0

    Cheers
    Darren

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Tab Control and Tabbing backwards(Shift+tab)

    Set the current tab in the txtName10 GotFocus event.

  6. #6
    Hyperactive Member
    Join Date
    Apr 2004
    Posts
    342

    Re: Tab Control and Tabbing backwards(Shift+tab)

    That is why it is better not to use the SSTab control. Go with the Microsoft Tab Control.

    Once you learn how to use the MS Tab Control, it is much nicer and you can do exactly what you want.

    The problem seems to be that when you tab in controls that are in an SSTab, it stays within the current tab.......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width