I have a Tab control on a form.
The tab control has several tabs.
On each one of these tabs I have a lot of controls (textboxes, checkboxes, commandbuttons, etc.)
When I use the keyboard to navigate through all the controls on the screen (by continuously pressing the tab key, I move from control to control, until I reach the last control on the current tab. Then when I press the tab key again and again, the focus is lost.
After investigation, I realized that the focus navigates to other controls on the screen that are on other tabs (other than the current tab)!!!
For example if the first tab is active (
tabMain.Tab = 0), and I keep pressing the tab key until I reach the last control on this
tabMain.Tab = 0, then after that when I press the tab key again, the focus goes to controls that are on
tabMain.Tab = 1 !!!
In order to prevent this bizzare behaviour I have created a Frame array. Each member of this Frame array which is an individual Frame, is placed on a different tab of the Tab control.
Then I have placed all controls that are supposed to be on a specific tab of the Tab control, on the corresponding Frame.
For example every control that is supposed to be on
tabMain.Tab = 0 is now on
fraMain(0) which is itself on
tabMain.Tab = 0.
And every control that is supposed to be on
tabMain.Tab = 1 is now on
fraMain(1) which is itself on
tabMain.Tab = 1.
And so on.
Now I am trying to write a generic piece of code to control the navigation problem:
Code:
Public Sub TabNavControl(ByRef TheTabCtrl As SSTab, ByRef TheFraCtrl As Frame)
Dim i As Long
Dim CurrTab As Long
Dim TabCount As Long
'Init
CurrTab = TheTabCtrl.Tab
TabCount = TheTabCtrl.Tabs
'Main
For i = 0 To TabCount - 1
TheFraCtrl(i).Enabled = (CurrTab = i)
Next i
End Sub
But the above procedure gives an error on this line "
TheFraCtrl(i).Enabled = (CurrTab = i)":
Compile error: Wrong number of arguments or invalid property assignment
If I change this line "
Public Sub TabNavControl(ByRef TheTabCtrl As SSTab, ByRef TheFraCtrl As Frame)"
to "
Public Sub TabNavControl(ByRef TheTabCtrl As SSTab, ByRef TheFraCtrl() As Frame)"
Then the above error goes away, but then the code that
calls the above procedure gives an error:
Code:
Private Sub tabMain_GotFocus()
Call TabNavControl(tabMain, fraMain())
End Sub
It gives this error: type mismatch: array or user-defined type expected
If I change "Call TabNavControl(tabMain,
fraMain())"
to "Call TabNavControl(tabMain,
fraMain)" (that is removing the parantheses), it still gives me the same error: type mismatch: array or user-defined type expected
Whatever change I make, it gives me an error one way or the other.
How can I fix this?
Please advise.
Thanks.