SetFocus in Tab Control

darryaz

Registered User.
Local time
Today, 10:33
Joined
Nov 3, 2011
Messages
13
I have a form with a Tab control containing several fields. I have created a SetFocus statement for the "on click" property of each tab. If I click through the tabs in "forward" order (i.e. Left to Right) the SetFocus is exactly where I want it to be.

However, if I click through the tabs in "reverse" order (i.e. Right to Left) the focus is set to a different field.....and I want it to be on the same one as before.

Do I need an additional Setfocus statement for each tab? If so, where do I place it? Or is the solution something completely different?
 
Try setting the Tab Order of each of the tabs in your tab control. Make the first control in the tab order of each tab to be the one you want to have the focus and you will not need any code to set the focus to that control. If you want to set the focus to some control other than the first control in the Tab Order of a specific tab then you can use the OnClick event of each of the tabs and set the focus to any control you like. In this case, yes. you will need code for each of the tabs.
 
I have set the Tab Order for each tab in the control. When I click through the tabs in Right-to-Left order, Setfocus is on the LAST tab in the Tab Order.

Any idea why?
 
As it turns out, I forgot that the On Click event of each tab does not fire like you think it would. That event only fires when you actually click in the tab area not when you click on the tab at the top.

To have an action happen when you click on each of the tabs, try placing the following code in the Change event of the tab control (not each page).
Code:
Dim lngPageVal As Long
lngPageVal = Me.TabCtl0
Select Case lngPageVal
    Case 0  'Page1
        Me.NameOfControl.SetFocus
    Case 1  'Page2
        Me.NameOfControl.SetFocus
    Case 2  'Page3
        Me.NameOfControl.SetFocus
End Select

Just change the "NameOfControl" to the name of the control you want to have the focus in each of the tabs. You can add a Case for each additional control you have. This code uses the index value of the tab control. This value is first assigned to the "lngPageVal" variable and then that value is used as the value for the Select Case statement. The index numbering of the tabs in the tab control is zero based.
 
Glad to help. Sorry that I did not pick up on that in my first post. Guess it's a sign I am getting old. LOL
 

Users who are viewing this thread

Back
Top Bottom