Results 1 to 7 of 7
  1. #1
    joekuhn is offline Novice
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Posts
    18

    Navigate to subform form main form with code

    I have a main form with 4 subforms and would like to know how I can move the focus from the main form to the subform without the mouse point and click. My database is in access 2007 and I am using Vista.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    try:

    Code:
    me.subformcontrol.form.setfocus
    me.subformcontrol.form.controls("control name").setfocus

  3. #3
    joekuhn is offline Novice
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Posts
    18
    Thanks for your reply. When I use your suggested code focus is lost from the control in the main form but is not moved to the control I specified in the subform. Any suggestiond?

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    make sure the first line's "subform" part of the syntax references the subform's control and not the name of the actual form. that, above any other, is the mistake that is always made. surprisingly, it is also one of the few concepts in access that people never understand, as it is asked over and over again...

  5. #5
    joekuhn is offline Novice
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Posts
    18
    I usedthe subform's control as you suggested and shown in the code
    Me.Visits_Subform.Form.SetFocus
    Me.Visits_Subform.Form.Controls("Bags of Food").SetFocus
    It removes the focus from the control in the main form but does not set the focus on the "bags of food" control in the visits subform. If I press the Tab key it then shifts the focus to a subform which is the last tabstop on the main form. What am I doing wrong?

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by joekuhn View Post
    Me.Visits_Subform.Form.SetFocus
    Me.Visits_Subform.Form.Controls("Bags of Food").SetFocus
    try:
    Code:
    Me.Visits_Subform.SetFocus
    Me.Visits_Subform.Form.Controls
    I may have been wrong about using the word "form" in the first line. it's been eons since I've given advice on how to do this. I tested this, and it works fine:

    set focus to the subform control, then focus to one of the controls on that subform.

  7. #7
    joekuhn is offline Novice
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Posts
    18
    thank you very much. this did the trick.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. opening a second form from main/subform
    By PJPCVP in forum Database Design
    Replies: 1
    Last Post: 10-29-2010, 09:50 PM
  2. Subform won't display in main form
    By Lynn in forum Forms
    Replies: 15
    Last Post: 03-22-2010, 10:17 AM
  3. Linking Subform Control to Main form
    By KWarzala in forum Forms
    Replies: 1
    Last Post: 03-13-2010, 08:32 PM
  4. Replies: 1
    Last Post: 09-28-2009, 05:21 PM
  5. Subform vs main form calculation
    By fadone in forum Forms
    Replies: 17
    Last Post: 12-21-2005, 07:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums