• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 526
  • Last Modified:

Setting Focus on a Form with a SubForm

I'm having difficulty setting focus to a field on the subform. Here's the picture. On the search form I enter a claim number it then searches the the database to retrieve the individual associated with that claim if found it will bring up the history screen with the individuals name and address. On the form that it brings up will be a subform to enter the the date and other information. I want the focus to transfer to the date on the subform. Help.
0
RJWAGNER
Asked:
RJWAGNER
  • 2
  • 2
1 Solution
 
jmantha709Commented:
You need 2 lines and the syntax should look like :

Me.MySubformControlName.setfocus
Me.MySubformControlName.Form!MyControlName.SetFocus
0
 
RJWAGNERAuthor Commented:
Where and on which forms should these lines be add too.
0
 
jmantha709Commented:
Many possibles places...  depending on when you want the focus to move there...

You say you bring up a form...  One place for the code (if the form is not modal) could be right after that :

'I guess you have a docmd.openform somewhere...

Docmd.openform "MyFormName"...
Forms!MyFormName.MySubformControlName.setfocus
Forms!MyFormName.MySubformControlName.Form!MyControlName.SetFocus
0
 
thenelsonCommented:
I know you already got the answer.  Here is more info:

The form/subform (everything discussed here applies to a report/subreport also) confuses a lot of programmers. The concept of a subform is actually a misnomer. There really is not a thing called a subform. What we really have is a form contained within another form. There are three objects, the two forms and a subform container that holds the form within. To better illustrate this, it is actually possible to have a second copy of the main form in the subform container. The three objects each have a name. The subform container and the form within the container can share the same name (although for less confusion, it it better they do not have the same name.) The subform container has the link master and link child field properties that connect the two forms together.  Although the form within the container is just a form, we call it a subform.

When we first click on a subform, the subform container is highlighted. This is indicated by the appearance of the eight sizing handles on the subform container frame. The second time we click on the subform, the form within is highlighted indicated by the small square dot appearing in the upper, left corner of the form. The third time we click on a subform, a control within the form will be highlighted.

When you have nested subforms, this is repeated:
Main form
   Subform container within the main form
      Form within the subform container
         Subform container within the form (subform)
            Form within the nested subform container

To set focus on a control in the subform, we first have to set focus on the subform container:
Forms!MainFormName!SubformContainerName.SetFocus
Forms!MainFormName!SubformContainerName!ControlName.SetFocus

It you are in the main form, you can replace
Forms!MainFormName
with the Me keyword:
Me!SubformContainerName.SetFocus
Me!SubformContainerName!ControlName.SetFocus

A subform container nested within a subform is a control in the subform so you would set focus to it just like any other control in the subform. To set focus on a control in a nested subform, we have to drill down to it:
Forms!MainFormName!SubformContainerName.SetFocus
Forms!MainFormName!SubformContainerName!Sub-SubformContainerName.SetFocus
Forms!MainFormName!SubformContainerName!Sub-SubformContainerName!ControlName.SetFocus

We perform an action on or set the property of a subform container:
Forms!MainFormName!SubformContainerName.Requery
Forms!MainFormName!SubformContainerName.Visible = True

On a nested subform:
Forms!MainFormName!SubformContainerName!Sub-SubformContainerName.Requery
Forms!MainFormName!SubformContainerName!Sub-SubformContainerName.Visible = True
0
 
thenelsonCommented:
Glad to help and thank you very much for the points with "A" grade but didn't jmantha709 give you the correct answer first?  Shouldn't he get at least a share?

Happy Computing!

Nelson
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now