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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Focus on a subform 1

Status
Not open for further replies.

TwoOdd

Programmer
Sep 10, 2003
196
CL
I'm trying to set the focus on a field in the subform of a subform.

This works to set the focus on a field in the first subform:
Code:
Forms!frm_Main!frm_SubForm.Form.fld_ID.SetFocus

There is a subform called "frm_Revisions" on the subform "frm_SubForm" and I want to set the focus on a field in "frm_Revisions". For example:
Code:
Forms!frm_Main!frm_SubForm!frm_Revisions.Form.fld_RevID.SetFocus

But it just won't work. Any help on this would be much appreciated.

Thanks,

TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
You are short a form, and it is usually necessary to do this in two steps.

Code:
Forms!frm_Main!frm_SubForm.Form.SetFocus
Forms!frm_Main!frm_SubForm.Form!frm_Revisions.Form.fld_RevID.SetFocus

 
Still doesn't want to work. It sets the focus just fine to the main subform (and any field on that subform), but from there, I can't get it to focus on the nested subform.

I have even tried the following syntax:
Code:
Forms!frm_Main!frm_SubForm.Form!frm_Revisions.Form!fld_RevID.SetFocus

But again with no luck.

Any other ideas?

Thanks,


TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
There was a problem with subforms nested three deep, but it may be that you are experiencing a similar problem. The workaround, as far as I recall, is to reference the form and work down, for example:

Code:
Dim frm As Form

Set frm = Forms!frm_Main!frm_SubForm.Form
frm.SetFocus
frm.frm_Revisions.Form.fld_RevID.SetFocus

I guess you have checked the spelling and that you are referring to the subform control, not the form contained? These do not always have the same name.

 
It runs through the code without any errors popping up, but it just won't put the focus on the nested subform.

I have double and triple checked the spelling on the form names and fields and have tried to set the focus to multiple fields on the nested subform and still nothing.

I also have option explicit turned on to make sure all my variable references are set appropriately.

Thank you for your efforts.




TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
Okay, I finally got it to work. You're idea was on the right track. Here is the actual code that finally worked:
Code:
    Dim frm As Form
    Set frm = Forms!frm_Main.Form!frm_SubForm.Form
    frm.frm_Revisions.SetFocus
    frm.frm_Revisions.Form!fld_RevID.SetFocus
[\code]

Thanks Remou - a star for you :)

TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
 -- Barry LePatner
 
How are ya TwoOdd . . .

To my knowledge you have to set the focus to the subform control 1st (a subform is a control on its parent form), before you can set focus to another control on that subform). Example:
Code:
[blue]   Dim s1 As Control, s2 As Control
   
   Set s1 = Forms!frm_Main!frm_SubForm
   Set s2 = s1.Form!sfrm2
   
   s1.SetFocus
   s2.SetFocus
   s2.Form!fld_RevID.SetFocus
   
   Set s2 = Nothing
   Set s1 = Nothing[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top