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. :confused:
It's easy done for Tab0 to Tab1 buy putting code in the last controls
Validate event of tab0:
VB Code:
Private Sub Text_Validate(Cancel As Boolean)
SSTab1.Tab = 1
End Sub
So now I'm on the first control of Tab1 and I want too Tab backwards. Any ideas will be great :afrog:
Thanks
Darren
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:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'Assign actual Tab to Variable
Dim intActualTab As Integer
intActualTab = SSTab1.Tab
'Change Down SSTab
If KeyCode = vbKeyPageDown & vbKeyControl Then
'First Tab
If SSTab1.Tab > 0 Then
SSTab1.Tab = intActualTab - 1
End If
End If
'Change UP SSTab
If KeyCode = vbKeyPageUp & vbKeyControl Then
'Last Tab
If SSTab1.Tab < SSTab1.Tabs - 1 Then
SSTab1.Tab = intActualTab + 1
End If
End If
End Sub
Many softwares, like Excel, use Ctrl PageUp and Ctrl PageDown to browse trough Tabs...
I hope this will help you...
Re: Tab Control and Tabbing backwards(Shift+tab)
I have found that this code below works best.
VB Code:
Private Sub SSTab1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 9
Dim intCounter As Integer
With SSTab1
If Shift = 1 Then
intCounter = -1 + .Tab
Else
intCounter = 1 + .Tab
End If
Select Case intCounter
Case Is < 0
.Tab = .Tabs - 1
Case Is > .Tabs - 1
.Tab = 0
Case Else
.Tab = intCounter
End Select
End With
End Select
End Sub
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
Re: Tab Control and Tabbing backwards(Shift+tab)
Set the current tab in the txtName10 GotFocus event.
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.......