Wrong focus when switching among pages of TAB control (1 Viewer)

Richard1980

Registered User.
Local time
Today, 17:00
Joined
Aug 13, 2012
Messages
72
Hello folks,
I have a form with a TAB control and four pages. Each control of each page has his TAB index set correctly (starting from 0 to n), some of controls are not enabled to be tabbed. The form's cycle is set on "Current page".
I have two kind of problems.
First: I am on the last control of the page, pressing TAB key the focus gets invisible. Press TAB key again and the focus moves on the first page's control. For each page happens this behaviour.
Second: clicking randomly on the TAB pages the focus is not always on the control with TAB index 0, but usually on the last.
I have read that clicking on a new page the focus should be automatically on the first control, but this does not happen in my experience.
Any suggestion?
Thanks, bye.

Riccardo
 

Richard1980

Registered User.
Local time
Today, 17:00
Joined
Aug 13, 2012
Messages
72
No one can help me or experienced tha same issue?
Thanks.
 

Richard1980

Registered User.
Local time
Today, 17:00
Joined
Aug 13, 2012
Messages
72
Hello,
it is a some month ago thread strated by me, but I am still struggling with this "problem" (I don't know really if it is a problem).
Anyway, when switching between pages, randomnly only the focus goes onto the first control, which has the Tab index set as 0.
Does anyone have a solution or experienced the same issue?
Thanks, bye.
 

boblarson

Smeghead
Local time
Today, 08:00
Joined
Jan 12, 2001
Messages
32,059
Hello folks,
I have a form with a TAB control and four pages. Each control of each page has his TAB index set correctly (starting from 0 to n), some of controls are not enabled to be tabbed. The form's cycle is set on "Current page".
I have two kind of problems.
First: I am on the last control of the page, pressing TAB key the focus gets invisible. Press TAB key again and the focus moves on the first page's control. For each page happens this behaviour.
Second: clicking randomly on the TAB pages the focus is not always on the control with TAB index 0, but usually on the last.
I have read that clicking on a new page the focus should be automatically on the first control, but this does not happen in my experience.
Any suggestion?
Thanks, bye.

Riccardo
You can't tab between tabs natively. So, if you want to move on to the next tab when you get to the end, this is what I do.

1. Create a text box on each tab and leave it unbound and set its height and width to something very tiny, like .01".

2. Then set it so that text box is the last in the tab order for that tab's controls.

3. Add code in the Got Focus event of that text box so that it moves you to the next tab.

Code:
Me.YourMainTabControlNameHere = Me.YourMainTabControlNameHere + 1

To make sure that it sets focus to the actual starting control you would need to actually do that.

So, for tab 1 the last unbound tiny control's got focus code:
Code:
Me.YourMainTabControlNameHere = Me.YourMainTabControlNameHere + 1
Me.YourControlNameOnTab2Here.SetFocus

See if that helps at all.
 

Richard1980

Registered User.
Local time
Today, 17:00
Joined
Aug 13, 2012
Messages
72
You can't tab between tabs natively. So, if you want to move on to the next tab when you get to the end, this is what I do.

1. Create a text box on each tab and leave it unbound and set its height and width to something very tiny, like .01".

2. Then set it so that text box is the last in the tab order for that tab's controls.

3. Add code in the Got Focus event of that text box so that it moves you to the next tab.

Code:
Me.YourMainTabControlNameHere = Me.YourMainTabControlNameHere + 1

To make sure that it sets focus to the actual starting control you would need to actually do that.

So, for tab 1 the last unbound tiny control's got focus code:
Code:
Me.YourMainTabControlNameHere = Me.YourMainTabControlNameHere + 1
Me.YourControlNameOnTab2Here.SetFocus

See if that helps at all.
Hi Bob,
thanks for your help.
I have just tried your suggestion, it works but not perfectly. In other words, I can move through different pages with TAB key, but when I move to the second page and I click on the first TAB page the focus still remains in the second page, only by pressing several times the focus returns to the first page, quite strange indeed.

Another way I tried to get the correct focus when changing the page, was to set the focus on the Click event of tab page, but It works randomnly, don't know why. Sometimes the focus goes to the first textbox, sometimes (playing between pages) goes to the other ones. Quite strange indeed again.

Code:
Private Sub tabPage2_Click()
txt1.setfocus
End Sub

Any more suggestion?
Thanks, bye.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 16:00
Joined
Sep 12, 2006
Messages
15,651
i didn't think you could have a tab order of zero.

my tab orders always start with tab order 1. maybe the zero tab stop is causing the confusion.

if you want particular tabs not to be in the taborder, you can set tabstop to NO
 

Richard1980

Registered User.
Local time
Today, 17:00
Joined
Aug 13, 2012
Messages
72
Hi Dave,
I don't know about it, the TAB order=0 is that the system assign automatically when I place controls into the form.
Moreover, I have just tried to rename the TAB order of a form with four controls: 1,2,3,4. While modifying the fourth TAB order's control, a window message told me that orders must go from 0 to 3.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 16:00
Joined
Sep 12, 2006
Messages
15,651
sorry. my bad.

I just checked, and you are right about the tab index starting at 0.
 

boblarson

Smeghead
Local time
Today, 08:00
Joined
Jan 12, 2001
Messages
32,059
The click event is essentially useless in a tab control. You need to use the ON CHANGE event instead and then evaluate which tab was selected.

So, like
Code:
Private Sub TabControlNameHere_Change()
    Select Case TabControlNameHere
    Case 1
       Me.FirstControlNameOnTab1Here.SetFocus
    Case 2
       Me.FirstControlNameOnTab2Here.SetFocus
    ' ...etc.
 End Select
End Sub
 

missinglinq

AWF VIP
Local time
Today, 11:00
Joined
Jun 20, 2003
Messages
6,423
Bob is, of course, right on the money! The OnClick event of a Page of a Tabbed Control only fires if the Page itself is clicked on, not when the 'tab' of the Page is clicked on, which does make it basically useless! You have to be very careful when using any Control's OnClick event, because how they work varies greatly, from Control to Control.

Linq ;0)>
 

Users who are viewing this thread

Top Bottom