With VBA, how to put the 'tab' portion of the page in focus such that user can then key left/right arrows to select other pages. The tab should then visually indicate it has keyboard focus.
myTabCtl.Value = 0 and myTabCtl.Pages(0).SetFocus work but they don't give the page tab keyboard focus.
TIA,
Peter T
Access, 'select' the actual 'tab' of a TabControl Page
-
- NewLounger
- Posts: 18
- Joined: 27 Dec 2021, 12:17
-
- Administrator
- Posts: 78608
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Access, 'select' the actual 'tab' of a TabControl Page
I don't know the answer to your question (I don't think it's possible), but the user can switch tabs using Ctrl+Tab and Shift+Ctrl+Tab.
Best wishes,
Hans
Hans
-
- NewLounger
- Posts: 18
- Joined: 27 Dec 2021, 12:17
Re: Access, 'select' the actual 'tab' of a TabControl Page
I thought I had it working a few years ago but maybe my memory is wrong and you are right!
I appreciate user can switch between tabs with Ctrl+Tab, but if possible would I'd like to visually select the tab. Not essential though.
Thanks,
Peter
I appreciate user can switch between tabs with Ctrl+Tab, but if possible would I'd like to visually select the tab. Not essential though.
Thanks,
Peter
-
- 4StarLounger
- Posts: 564
- Joined: 27 Jun 2021, 10:46
Re: Access, 'select' the actual 'tab' of a TabControl Page
Does using SendKeys to send CTL-TAB immediately after either myTabCtl.Value = 0 and myTabCtl.Pages(0).SetFocus not put you into the state you want?
-
- NewLounger
- Posts: 18
- Joined: 27 Dec 2021, 12:17
Re: Access, 'select' the actual 'tab' of a TabControl Page
@SpeakEasy, unfortunately not but thanks for the suggestion.
SendKeys "^{TAB}" (Ctrl-Tab) activates the next page (as expected but not what I want) does not result in indicating the page-tab is 'selected' for keyboard input.
Also curiously, after the SendKeys, clicking a page tab now fails to put it in visual focus for the rest of the session. Though tabbing controls between tabIndex=0 and the last tabindex still does.
Peter T
SendKeys "^{TAB}" (Ctrl-Tab) activates the next page (as expected but not what I want) does not result in indicating the page-tab is 'selected' for keyboard input.
Also curiously, after the SendKeys, clicking a page tab now fails to put it in visual focus for the rest of the session. Though tabbing controls between tabIndex=0 and the last tabindex still does.
Peter T
-
- 4StarLounger
- Posts: 564
- Joined: 27 Jun 2021, 10:46
Re: Access, 'select' the actual 'tab' of a TabControl Page
Interesting. Works here with Access 2016. Mind you - so does the basic SetFocus method that you list as not working ...
On the other hand, you also say " key left/right arrows to select other pages" and I'm not sure this has ever been the behavior of the tabcontrol in MS Access. The arrow keys normally work (almost) exactly like tab and ctl-tab to navigate between tabindexed controls on the page, rather than between pages
On the other hand, you also say " key left/right arrows to select other pages" and I'm not sure this has ever been the behavior of the tabcontrol in MS Access. The arrow keys normally work (almost) exactly like tab and ctl-tab to navigate between tabindexed controls on the page, rather than between pages
-
- NewLounger
- Posts: 18
- Joined: 27 Dec 2021, 12:17
Re: Access, 'select' the actual 'tab' of a TabControl Page
Page.SetFocus works, as in it doesn't fail, but what it seems to do is set to whatever control has Tabindex = 0 as the new activeControl, which I don't want, and doesn't visually highlight the page tab.
I've tested in 2010, 2013, 2016 and 365 and all seem to work similarly as I described, including use of SendKeys Ctrl-Tab. When the tab (with the page caption) is selected and highlighted (manually with a click or keyboard tabbing between controls with the last tabindex and tabindex 0) user can then cycle pages both with (Shift)Ctrl-Tab and the left/right arrows.
Peter T
I've tested in 2010, 2013, 2016 and 365 and all seem to work similarly as I described, including use of SendKeys Ctrl-Tab. When the tab (with the page caption) is selected and highlighted (manually with a click or keyboard tabbing between controls with the last tabindex and tabindex 0) user can then cycle pages both with (Shift)Ctrl-Tab and the left/right arrows.
Peter T
-
- Administrator
- Posts: 78608
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Access, 'select' the actual 'tab' of a TabControl Page
I have used all versions of Access since Access 95, but I have never been able to use the left and right arrow keys to switch tabs, regardless of what I select manually or in code. I always have to use (Shift+)Ctrl+Tab.
I usually provide an accelerator key in the caption of each tab, so that a tab can be selected by pressing Alt+accelerator.
I usually provide an accelerator key in the caption of each tab, so that a tab can be selected by pressing Alt+accelerator.
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 564
- Joined: 27 Jun 2021, 10:46
Re: Access, 'select' the actual 'tab' of a TabControl Page
>what it seems to do is set to whatever control has Tabindex = 0
Yep, I'd expect that
>which I don't want
Which is why I advised the SendKey solution, which switches the focus to the tab itself of the page in question. At least, it does here
>doesn't visually highlight the page tab
Wouldn't expect that. And that doesn't happen here. Tab highlights as expected
>cycle pages ... with the left/right arrows
As I said above, I've not observed this navigation behaviour with the default Access tabcontrol. HansV seems to confirm this
Sop all a bit odd
Yep, I'd expect that
>which I don't want
Which is why I advised the SendKey solution, which switches the focus to the tab itself of the page in question. At least, it does here
>doesn't visually highlight the page tab
Wouldn't expect that. And that doesn't happen here. Tab highlights as expected
>cycle pages ... with the left/right arrows
As I said above, I've not observed this navigation behaviour with the default Access tabcontrol. HansV seems to confirm this
Sop all a bit odd
-
- NewLounger
- Posts: 18
- Joined: 27 Dec 2021, 12:17
Re: Access, 'select' the actual 'tab' of a TabControl Page
Hans and SpeakEasy,
Yes it is odd. I created a new test form with a tabControl etc and what I described about visually selecting the tab (ie the page-caption) and then can use left/right arrows didn’t work at all, as you guys would expect. I returned to my original form and that didn’t work as I described either. But after some more messing around then it did, and still does!
When it’s working and the tab is visually selected, the the TabControl becomes form’s ActiveControl, and remains the ActiveControl when cycling pages with left/right arrows or Ctrl-Tab. Slightly curious as the TabControl doesn’t expose a SetFocus method, as its Pages do.
After Ctrl-Tab from any other control the adjacent page is activated, and this Page is now the form’s ActiveControl. Use of SendKeys also activates the next page and sets it as the current ActiveControl.
So it would seem what I need to do is put the tabControl in focus as the ActiveControl…
To clarify, for my objective I’m not trying to activate or change to a different page, which SendKeys does and one reason it doesn’t help. The other being it disables the visual page selection for the rest of the session.
In the big scheme of things it’s not an important objective. It’s only a small detail trying to replicate what I’ve seen as default behaviour, albeit with an unusual scenario!
Peter T
Yes it is odd. I created a new test form with a tabControl etc and what I described about visually selecting the tab (ie the page-caption) and then can use left/right arrows didn’t work at all, as you guys would expect. I returned to my original form and that didn’t work as I described either. But after some more messing around then it did, and still does!
When it’s working and the tab is visually selected, the the TabControl becomes form’s ActiveControl, and remains the ActiveControl when cycling pages with left/right arrows or Ctrl-Tab. Slightly curious as the TabControl doesn’t expose a SetFocus method, as its Pages do.
After Ctrl-Tab from any other control the adjacent page is activated, and this Page is now the form’s ActiveControl. Use of SendKeys also activates the next page and sets it as the current ActiveControl.
So it would seem what I need to do is put the tabControl in focus as the ActiveControl…
To clarify, for my objective I’m not trying to activate or change to a different page, which SendKeys does and one reason it doesn’t help. The other being it disables the visual page selection for the rest of the session.
In the big scheme of things it’s not an important objective. It’s only a small detail trying to replicate what I’ve seen as default behaviour, albeit with an unusual scenario!
Peter T