Referencing subform from another subform

B

BobT

I have a main form.

There are two subforms on this main form. When a control has focus on
subform 1, after it is updated I want to reference the control on the second
subform. This is Access 2003. What is the syntax to do this? I have tried

Forms![MainForm]![Subform2].Form!Control.SetFocus

which doesn't seem to work.
 
S

Shiller

S

Shiller

S

Shiller

I have a main form.

There are two subforms on this main form.  When a control has focus on
subform 1, after it is updated I want to reference the control on the second
subform.  This is Access 2003.  What is the syntax to do this?  I have tried

Forms![MainForm]![Subform2].Form!Control.SetFocus

which doesn't seem to work.

Bob,

The syntax is Me.ControlName

Check out the following site for more info: http://www.mvps.org/access/forms/frm0031.htm

Shiller
http://sites.google.com/site/microsoftaccesstips/
 
S

Shiller

I have a main form.

There are two subforms on this main form.  When a control has focus on
subform 1, after it is updated I want to reference the control on the second
subform.  This is Access 2003.  What is the syntax to do this?  I have tried

Forms![MainForm]![Subform2].Form!Control.SetFocus

which doesn't seem to work.


Bob,

The syntax is Me.ControlName

Check out the following site for more info: http://www.mvps.org/access/forms/frm0031.htm

Shiller
http://sites.google.com/site/microsoftaccesstips/
 
D

Dirk Goldgar

(re-posting, as my original reply hasn't appeared)

BobT said:
I have a main form.

There are two subforms on this main form. When a control has focus on
subform 1, after it is updated I want to reference the control on the
second
subform. This is Access 2003. What is the syntax to do this? I have
tried

Forms![MainForm]![Subform2].Form!Control.SetFocus

which doesn't seem to work.


To set the focus to a control on a subform from the main form (or from some
other subform of the main form), you have to set the focus to the control
(on the subform) *and also* set the focus to the subform itself. That's two
separate SetFocus commands. Try this:

Me.Parent![Subform2].SetFocus
Me.Parent![Subform2].Form!Control.SetFocus

Contrary to popular belief, it doesn't matter in what order those statements
are executed. The reason you have to set focus twice is that both the
parent form and the subform have an active control, and the two are
independent of each other. Only when the subform itself is the main form's
active control will the effective focus be in the subform's active control.
 
B

BobT

Dirk,

Thanks! This worked perfectly! Where can one find this type of reference
information. I looked everywhere and spent hours on this issue.........

This is one reason why I am SO critical of Microsoft documentation......

--
BT


Dirk Goldgar said:
(re-posting, as my original reply hasn't appeared)

BobT said:
I have a main form.

There are two subforms on this main form. When a control has focus on
subform 1, after it is updated I want to reference the control on the
second
subform. This is Access 2003. What is the syntax to do this? I have
tried

Forms![MainForm]![Subform2].Form!Control.SetFocus

which doesn't seem to work.


To set the focus to a control on a subform from the main form (or from some
other subform of the main form), you have to set the focus to the control
(on the subform) *and also* set the focus to the subform itself. That's two
separate SetFocus commands. Try this:

Me.Parent![Subform2].SetFocus
Me.Parent![Subform2].Form!Control.SetFocus

Contrary to popular belief, it doesn't matter in what order those statements
are executed. The reason you have to set focus twice is that both the
parent form and the subform have an active control, and the two are
independent of each other. Only when the subform itself is the main form's
active control will the effective focus be in the subform's active control.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
M

Marshall Barton

Dirk said:
To set the focus to a control on a subform from the main form (or from some
other subform of the main form), you have to set the focus to the control
(on the subform) *and also* set the focus to the subform itself. That's two
separate SetFocus commands. Try this:

Me.Parent![Subform2].SetFocus
Me.Parent![Subform2].Form!Control.SetFocus

Contrary to popular belief, it doesn't matter in what order those statements
are executed. The reason you have to set focus twice is that both the
parent form and the subform have an active control, and the two are
independent of each other. Only when the subform itself is the main form's
active control will the effective focus be in the subform's active control.


Dirk, this is the best explanation I have ever seen re this
issue. It sure helped me get a clearer understanding of why
this code is needed and I am glad you posted it.
 
D

Dirk Goldgar

BobT said:
Dirk,

Thanks! This worked perfectly! Where can one find this type of reference
information. I looked everywhere and spent hours on this issue.........

This is one reason why I am SO critical of Microsoft documentation......


I know what you mean. A lot of detailed technical documentation is
available, but much less information about how to use it in a practical
context.

In this case, just googling for "Access setfocus subform control" brings up
a bunch of helpful hits, of which the first (at the moment) is this MS
KnowledgeBase article:

http://support.microsoft.com/kb/294212
How to select controls on a subform with setFocus method in Access 2002

So in all fairness, you can't really say the info isn't there at all -- in
this case.

Here are some great online resources for how-to information:

http://www.mvps.org/access/
The Access Web

http://www.allenbrowne.com/tips.html
Allen Browne's Tips

http://www.granite.ab.ca/accsmstr.htm
Tony Toews' Main Microsoft Access Page

http://www.lebans.com/
Stephen Lebans (for deep magic)

Using Google Groups to search these newsgroups is always the first thing I
do when I have a question:

http://groups.google.com/advanced_search?q=group:*access*
Google Groups Advanced Search (Access)

And it's often worth searching the KnowledgeBase, but you have to separate a
lot of chaff from the wheat:

http://support.microsoft.com/search/?adv=1
Microsoft Help and Support, Advanced Search


Among offline resource, good books for Access developers include:

Access 2002 Developers Handboook
by Litwin, Getz, and Gunderloy, from Sybex

Microsoft Access 2003 Inside Out
by John Viescas, from Microsoft Press

Building Microsoft Access Applications
by John Viescas, from Microsoft Press

Those are all pre-Access-2007, so some material is out of date if you're
working wth A2007 (especially anything concerning toolbars), but the rest is
still relevant and useful.
 
B

BobT

Dirk,

I did perform a few searches and didn't run into that
document.........Google searches are great, but complete reference
documentation in practical terms would be of even greater use........

With Oracle documentation I can get excellent reference manuals with
examples in practical terms.....

Thanks again,
Bob
 
D

Dirk Goldgar

BobT said:
Dirk,

I did perform a few searches and didn't run into that
document.........Google searches are great, but complete reference
documentation in practical terms would be of even greater use........

I agree completely. The last time we had that with Access was Access 97.
Many old-time developers still keep a copy of the Access 97 help files on
their computers.
With Oracle documentation I can get excellent reference manuals with
examples in practical terms.....

And yet, whenever I have tried to find out how to do something in the Oracle
docs, I can't find it. Probably that's because I only dabble in Oracle, and
so don't know the right place to look.
 
D

Dirk Goldgar

Marshall Barton said:
Dirk, this is the best explanation I have ever seen re this
issue. It sure helped me get a clearer understanding of why
this code is needed and I am glad you posted it.


Gee, thanks, Marsh.
 

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