Setting Focus on a Form with a SubForm

Posted on 2006-04-07
Last Modified: 2006-11-18
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.
Question by:RJWAGNER
    LVL 15

    Expert Comment

    You need 2 lines and the syntax should look like :


    Author Comment

    Where and on which forms should these lines be add too.
    LVL 15

    Expert Comment

    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"...
    LVL 39

    Accepted Solution

    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:

    It you are in the main form, you can replace
    with the Me keyword:

    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:

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

    On a nested subform:
    Forms!MainFormName!SubformContainerName!Sub-SubformContainerName.Visible = True
    LVL 39

    Expert Comment

    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!


    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
    Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now