Setting focus to a subform on a Tab Control

  • Thread starter Jennifer Eckel-Naborowski via AccessMonster.com
  • Start date
J

Jennifer Eckel-Naborowski via AccessMonster.com

Hi, I'm familiar with Access, but new to the VB programming side.

Here's what I'm trying to do. I have a main form (Orders). I have a subform
(ProjectTransition). I have a tab control (tabCtl160). I'm trying to get
the focus from my main form to the subform. The subform is on a page inside
a tab control that resides on the main form. I have successfully set the
focus to the Page on the tab control, but can't get the focus to move onto
the subform that sits on that page. Here's my code.

Forms("Orders").Controls("tabCtl160").Pages(2).SetFocus

Not sure if this is important, but the data on the main form and the data
on the subform come from the same table.

Any help is appreciated.

jenn
 
D

Dirk Goldgar

"Jennifer Eckel-Naborowski via AccessMonster.com"
Hi, I'm familiar with Access, but new to the VB programming side.

Here's what I'm trying to do. I have a main form (Orders). I have a
subform (ProjectTransition). I have a tab control (tabCtl160). I'm
trying to get the focus from my main form to the subform. The subform
is on a page inside a tab control that resides on the main form. I
have successfully set the focus to the Page on the tab control, but
can't get the focus to move onto the subform that sits on that page.
Here's my code.

Forms("Orders").Controls("tabCtl160").Pages(2).SetFocus

Not sure if this is important, but the data on the main form and the
data on the subform come from the same table.

Any help is appreciated.

jenn

Have you tried just setting the focus directly to the subform control?
By "subform control", I mean the control on the main form that presents
the subform to the user. That control may or may not have the same name
as the form object that it displays, its Source Object. You should be
able just to set the focus to that control, by name, like this:

Forms!Orders!NameOfSubformControl.SetFocus

or

Forms("Orders").Controls("NameOfSubformControl").SetFocus

or, if the code is executing on the main form,

Me!NameOfSubformControl.SetFocus

You should not need to set the focus to the tab control first.
 
J

Jennifer Eckel-Naborowski via AccessMonster.com

Dirk -

Thanks for responding. When I set the focus directly to the subform control
I get the following error message "Object doesn't support this property or
method."

I neglected to say in my last post that there is one more form (Won
Opportunity) between the main form and the subform. You select a value in a
combo box on the main form, it fires the Won Opportunity form which acts
like a message box that gives you the option to click "OK" or "Cancel". If
you click "OK" I want to hop to the subform. I currently have the code on
the OnClick event of the Won Opportunity form.

Any suggestions?

Jenn
 
D

Dirk Goldgar

"Jennifer Eckel-Naborowski via AccessMonster.com"
Dirk -

Thanks for responding. When I set the focus directly to the subform
control I get the following error message "Object doesn't support
this property or method."

I neglected to say in my last post that there is one more form (Won
Opportunity) between the main form and the subform.

You do realize that's a crucial piece of information, without which it
would be impossible for anyone to answer your question?
You select a
value in a combo box on the main form, it fires the Won Opportunity
form which acts like a message box that gives you the option to click
"OK" or "Cancel". If you click "OK" I want to hop to the subform. I
currently have the code on the OnClick event of the Won Opportunity
form.

Any suggestions?

Jenn

What do you mean "it fires the Won Opportunity form"? Is this separate
popup form of some sort, or is it another subform on the main form? Are
we talking about nested subforms? If "Won Oportunity" is a standalone
form, is it a modal form, or opened in dialog mode?

Where is the code going to run, that is supposed to set the focus to the
subform we were talking about. And while we're at it, what's the name
of the subform control?
 
J

Jennifer Eckel-Naborowski via AccessMonster.com

Sorry, lesson learned. Trying to provide the right about of information
without writing a book.

When you select the "Won" value from the combo box on the main form
"Orders", the form "Won Opportunity" launches. This is not a subform, but a
separate stand alone form. It is not a modal form. It only launches for the
value "Won".

The "Won Opportunity" form has a message on it remindering the user to fill
out the remaining information in the subform. If they click the OK button,
I'm trying to move the focus to the "ProjectTransition" subform (the
subform in question) to finish data entering. So the OnClick event on the
"OK" button is what is supposed to launch the code and bring up the
"ProjectTransition" subform. "ProjectTransition" is in a tab control, but I
think we determined that shouldn't make a difference.

Hope that provides a more complete picture. Thanks

Jenn
 
D

Dirk Goldgar

"Jennifer Eckel-Naborowski via AccessMonster.com"
Sorry, lesson learned. Trying to provide the right about of
information without writing a book.

When you select the "Won" value from the combo box on the main form
"Orders", the form "Won Opportunity" launches. This is not a subform,
but a separate stand alone form. It is not a modal form. It only
launches for the value "Won".

The "Won Opportunity" form has a message on it remindering the user
to fill out the remaining information in the subform. If they click
the OK button, I'm trying to move the focus to the
"ProjectTransition" subform (the subform in question) to finish data
entering. So the OnClick event on the "OK" button is what is supposed
to launch the code and bring up the "ProjectTransition" subform.
"ProjectTransition" is in a tab control, but I think we determined
that shouldn't make a difference.

Hope that provides a more complete picture. Thanks

The following code works fine for me in a test. If it doesn't work for
you -- after you've made any name corrections -- there's something I
don't understand about the setup:

'----- start of code for "OK" command button -----
Private Sub cmdOK_Click()

Forms!Orders!ProjectTransition.SetFocus
DoCmd.Close acForm, Me.Name

End Sub
'----- end of code for "OK" command button -----
 
J

Jennifer Eckel-Naborowski via AccessMonster.com

Dirk -

It worked this time. I must have had something different last time I tried.
Many thanks for all the help!


Jenn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top