Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to set focus to a subform? 1

Status
Not open for further replies.

b31luv

Technical User
Feb 21, 2002
171
US
I've searched, and still can't find the answer. I have 2 subforms on a form. The form links as such, Main form links to subform 1, and subform 2 links to subform 2. I can trasition into subform 1 with no problem by tabbing. However, I can't tab to subform 2.

I've tried code:
Forms![FmPrjctScope Subform].SetFocus

and believe you me, I've tried ever variation of this piece of code

Forms!FmPrjctScope Subform.SetFocus
Forms!FmPrjctScope_Subform.SetFocus

I've even put in the control I want to have the focus.
Forms!FmPrjctScope_Subform!Area.SetFocus

Still I keep getting the message that it can't find my subform. I checked the name and I've checled it twice I still don't know.

Can someone please tell me what's wrong?


 
Have you tried something like this ?
Forms![name of main form]![name of FmPrjctScope Subform control].Form!Area.SetFocus

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
How are ya b31luv . . . . .
b31luv said:
[blue]and subform 2 links to subform 2[/blue]
On the premise you meant [blue]subform 2 links to [purple]subform 1[/purple][/blue], on the properties window for each form, [blue]Other Tab[/blue], check the [purple]Cycle Property[/purple]. You may have to cycle through all the controls (of which subforms are considered controls), but you should be able to [blue]Tab Thru[/blue] to subform 2.

Calvin.gif
See Ya! . . . . . .
 
To set focus to a subforms subform thru code, one important part is - from where.

A subform is not recognized as an open form, but as a control on the form hosting it, and it would need to be referenced thru it. Another thing, is that what one uses to reference, is what's referred to as the subform control name, which might differ from the subform name, see for instance How to Refer to a Control on a Subform or Subreport for some more info.

To start with, the easiest way of obtaining the correct reference (subform control names), is to use the expression builder, either from the criteria row of a query, or a control in another form whilst this form is open. Double click thru forms, loaded forms, the main form, first subform, second subform, then a control on the second subform. This would give a reference looking something like this:

[tt]forms!frmMain!frmSub1.Form!frmSub2.Form.txtControl[/tt]

(with some brackets I've omitted, I'll use those names in the samples below)

To set focus to te second subform from the main form, depending on version, one might try:

[tt]forms!frmMain!frmSub1.Form!frmSub2.SetFocus[/tt]

But often one would need to do this in two steps (here also adding a third step, setting focus to a specific control):

[tt]forms!frmMain!frmSub1.SetFocus
forms!frmMain!frmSub1.Form!frmSub2.SetFocus
forms!frmMain!frmSub1.Form!frmSub2.Form!txtControl.SetFocus[/tt]

Using this from the main form, one can cut down a little, using the Me keyword:

[tt]Me!frmSub1.SetFocus
Me!frmSub1.Form!frmSub2.SetFocus
Me!frmSub1.Form!frmSub2.Form!txtControl.SetFocus[/tt]

Or if the process is performed from the first subform:

[tt]Me!frmSub2.SetFocus
Me!frmSub2.Form!txtControl.SetFocus[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top