By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,153 Members | 2,581 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,153 IT Pros & Developers. It's quick & easy.

Setting the focus on a subform's Tab

Ericks
P: 74
Setting focus is addressed through several questions on this forum but I find this so complicated that I need a taylormade answer.

I have a tabbed main form called "Compounds". On one of the tabs, called "Page75" is a tabbed subform called "RegistrationLaunchTogether" with one of its tabs called "Observations". How do I set the focus on this tab from outside the main form?
Dec 7 '07 #1
Share this Question
Share on Google+
14 Replies


Rabbit
Expert Mod 10K+
P: 12,383
Setting focus is addressed through several questions on this forum but I find this so complicated that I need a taylormade answer.

I have a tabbed main form called "Compounds". On one of the tabs, called "Page75" is a tabbed subform called "RegistrationLaunchTogether" with one of its tabs called "Observations". How do I set the focus on this tab from outside the main form?
Me.SubformName.Form.TabControlName.Pages("PageName")
Dec 7 '07 #2

Ericks
P: 74
Shouldn't the main form be mentioned also?
Dec 7 '07 #3

ADezii
Expert 5K+
P: 8,669
Setting focus is addressed through several questions on this forum but I find this so complicated that I need a taylormade answer.

I have a tabbed main form called "Compounds". On one of the tabs, called "Page75" is a tabbed subform called "RegistrationLaunchTogether" with one of its tabs called "Observations". How do I set the focus on this tab from outside the main form?
The following code will Set Focus to the RegistrationLaunchTogether SubForm on Page 75 outside the context of the Compounds Form. It assumes the Tab Control on Compounds is named TabControl. This is all I had time for at the moment:
Expand|Select|Wrap|Line Numbers
  1. Forms!Compounds!TabControl.Pages!Page75.Controls!RegistrationLaunchTogether.SetFocus
Dec 7 '07 #4

Ericks
P: 74
The following code will Set Focus to the RegistrationLaunchTogether SubForm on Page 75 outside the context of the Compounds Form. It assumes the Tab Control on Compounds is named TabControl. This is all I had time for at the moment:
Expand|Select|Wrap|Line Numbers
  1. Forms!Compounds!TabControl.Pages!Page75.Controls!RegistrationLaunchTogether.SetFocus

Ok, that I assume will put the focus on the subcontrol. But I need to go one step further, namely to put the focus on the subcontrol's tab called "Observations"
Dec 7 '07 #5

Ericks
P: 74
Ok, that I assume will put the focus on the subcontrol. But I need to go one step further, namely to put the focus on the subcontrol's tab called "Observations"
ADezii, your code worked in that it set focus to the tabbed subform. That's already great. But I need to go as said one step further, to a tab on that subform
So just to put all the objects together:

Mainform: Compounds
Tab control of Mainform: TabCtl16
Tab of Mainform: Page75
Subform: RegistrationLaunchTogether
Tab control of Subform: TabCtl0
Tab of Subform: Observations

So what should I add to your code to set the focus on Observations outside the context of the Compounds Form
Dec 8 '07 #6

ADezii
Expert 5K+
P: 8,669
ADezii, your code worked in that it set focus to the tabbed subform. That's already great. But I need to go as said one step further, to a tab on that subform
So just to put all the objects together:

Mainform: Compounds
Tab control of Mainform: TabCtl16
Tab of Mainform: Page75
Subform: RegistrationLaunchTogether
Tab control of Subform: TabCtl0
Tab of Subform: Observations

So what should I add to your code to set the focus on Observations outside the context of the Compounds Form
It hasn't been tested, but something in the order of:
Expand|Select|Wrap|Line Numbers
  1. Forms!Compounds!TabCtl16.Pages!Page75.Controls!R  egistrationLaunchTogether.Form!TabCtl0.Pages!Observations.SetFocus
  2.  
Dec 8 '07 #7

Ericks
P: 74
It hasn't been tested, but something in the order of:
Expand|Select|Wrap|Line Numbers
  1. Forms!Compounds!TabCtl16.Pages!Page75.Controls!R  egistrationLaunchTogether.Form!TabCtl0.Pages!Observations.SetFocus
  2.  
With this code the main form opens but it doesn't go to tab Page75. It stays on the first Tab. But when I click on tab Page75 the focus on the Subform is on the Observations tab. So I added your first code as second line and now it works. It looks like this:

Forms!Compounds!TabCtl16.Pages!Page75.Controls!Reg istrationLaunchTogether.Form!TabCtl0.Pages!Observa tions.SetFocus
Forms!Compounds!TabCtl16.Pages!Page75.Controls!Reg istrationLaunchTogether.SetFocus
Dec 8 '07 #8

ADezii
Expert 5K+
P: 8,669
With this code the main form opens but it doesn't go to tab Page75. It stays on the first Tab. But when I click on tab Page75 the focus on the Subform is on the Observations tab. So your code did something "behind the scenes" but stayed at the first tab.
Here is a Method that I have tested and it does, in fact, work:
  1. Assign a Hot Key (&O) combination to the Observations Tab (set the Name = &Observations).
  2. The following code will activate that Tab (Observations) on the Sub-Form:
    Expand|Select|Wrap|Line Numbers
    1. Forms!Compounds!TabCtl16.Pages!Page75.Controls!RegistrationLaunchTogether.SetFocus
    2. SendKeys "%O"
    3.  
  3. It is not very elegant, but it does work.
Dec 8 '07 #9

Ericks
P: 74
Here is a Method that I have tested and it does, in fact, work:
  1. Assign a Hot Key (&O) combination to the Observations Tab (set the Name = &Observations).
  2. The following code will activate that Tab on the Sub-Form:
    Expand|Select|Wrap|Line Numbers
    1. Forms!Compounds!TabControl.Pages!Page75.Controls!RegistrationLaunchTogether.SetFocus
    2. SendKeys "%O"
    3.  
  3. It is not very elegant, but it does work.
As written above, this is what I did and now it seems to work:

1. Forms!Compounds!TabCtl16.Pages!Page75.Controls!Reg istrationLaunchTogether.Form!TabCtl0.Pages!Observa tions.SetFocus

2. Forms!Compounds!TabCtl16.Pages!Page75.Controls!Reg istrationLaunchTogether.SetFocus

Important is that it works but I'm curious tio know why it needs the two lines...

So thanks a lot. It worked. Highly appreciated.

Eric
Dec 8 '07 #10

Jim Doherty
Expert 100+
P: 897
Here is a Method that I have tested and it does, in fact, work:
  1. Assign a Hot Key (&O) combination to the Observations Tab (set the Name = &Observations).
  2. The following code will activate that Tab (Observations) on the Sub-Form:
    Expand|Select|Wrap|Line Numbers
    1. Forms!Compounds!TabCtl16.Pages!Page75.Controls!RegistrationLaunchTogether.SetFocus
    2. SendKeys "%O"
    3.  
  3. It is not very elegant, but it does work.
Hi Dez,

Just offering my two penneth FWIW to the posting (you might want to include a mention to this in the 'howto' article 'referring to tab controls' I've just read on here if you consider it helpful?)

Tab controls form part of a form object so you can refer to them explicitly by name including the pages of a tab....

Me!SubformName!RegistrationLaunchTogether.SetFocus
or
Me!SubformName.form.RegistrationLaunchTogether.Set Focus
or
Me!SubformName.form!RegistrationLaunchTogether.Set Focus

does what the poster requires so drilling down the hierachy through to the controls collection is not actually needed. In addition it also caters for the situation where they 'might' delete a tab page at some point causing the index number to shift. I've seen several postings where they are hard coding the index number in, and of course that can alter things significantly at runtime with the wrong page being selected because there hitherto absolute reference has been broken.

I agree with the poster referring to them is confusing to the newbie

Regards

Jim :)
Dec 8 '07 #11

ADezii
Expert 5K+
P: 8,669
Hi Dez,

Just offering my two penneth FWIW to the posting (you might want to include a mention to this in the 'howto' article 'referring to tab controls' I've just read on here if you consider it helpful?)

Tab controls form part of a form object so you can refer to them explicitly by name including the pages of a tab....

Me!SubformName!RegistrationLaunchTogether.SetFocus
or
Me!SubformName.form.RegistrationLaunchTogether.Set Focus
or
Me!SubformName.form!RegistrationLaunchTogether.Set Focus

does what the poster requires so drilling down the hierachy through to the controls collection is not actually needed. In addition it also caters for the situation where they 'might' delete a tab page at some point causing the index number to shift. I've seen several postings where they are hard coding the index number in, and of course that can alter things significantly at runtime with the wrong page being selected because there hitherto absolute reference has been broken.

I agree with the poster referring to them is confusing to the newbie

Regards

Jim :)
Hell Jim, your two penneth is always welcome and definately appreciated.
Dec 9 '07 #12

Ericks
P: 74
Hell Jim, your two penneth is always welcome and definately appreciated.
whilst this newbie witnesses the discussion in a state of amazed admiration and profound bewilderment exclaiming to the Gods of VBA, not worthy, not worthy...

Great job you guys. I'm glad there is this forum.
Dec 9 '07 #13

ADezii
Expert 5K+
P: 8,669
whilst this newbie witnesses the discussion in a state of amazed admiration and profound bewilderment exclaiming to the Gods of VBA, not worthy, not worthy...

Great job you guys. I'm glad there is this forum.
We are just as glad to have you aboard.
Dec 9 '07 #14

Jim Doherty
Expert 100+
P: 897
whilst this newbie witnesses the discussion in a state of amazed admiration and profound bewilderment exclaiming to the Gods of VBA, not worthy, not worthy...

Great job you guys. I'm glad there is this forum.
You're very welcome Ericks,

As for profound bewilderment I remember feeling that way once many years ago when I first picked up a mouse pointing it at the monitor expecting to change channels :)

Jim :)
Dec 9 '07 #15

Post your reply

Sign in to post your reply or Sign up for a free account.