Share via

How do I switch focus between multiple forms in Access?

Anonymous
2012-02-29T18:15:25+00:00

I have multiple forms in access, How can I set focus on "Form1" on load event of "Form2"?

I tried the below method, but it doesn't work. The focus is still on "Form2"

Private Sub Form_Load() 

DoCmd.OpenForm "Form1"

Forms!Form1.SetFocus

End Sub

I have selected "Form2" in "Display Form:" option in "Access Options", I am opening "Form1" in "Form2" Load event and then trying to set focus to "Form1"

Thanks in advance

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-03-01T01:22:25+00:00

I just created the test database in A2007 and I found the same thing as you.

I looked at some of my apps and I see that I open my start up form in hidden mode, so I was not aware of your issue.

Maybe you need a 3rd form as the startup form. Open it hidden, let it open Form2.

Put code on the unload event of Form2 or Form1 to close the 3rd form. Note: this idea has not been tested.

Was this answer helpful?

0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-02-29T21:36:35+00:00

    I just created a test database in A2010.

    I created 2 forms - frm1 and frm2.

    No code on frm1 - only code on frm2 is the code to open frm1.

    I set frm2 as the startup form in options.

    When the database opens, frm2 is open and frm1 is open and frm1 has the focus.

    You can do the same test.

    It seems that there is some other code running in your database that is preventing form1 from getting the focus.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-02-29T21:30:00+00:00

    Usually the last opened form gets the focus.

    What code could be still running on Form2 after the line of code that opens Form1?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-02-29T19:39:30+00:00

    Thanks for helping Jeanette,

    The end result would be Both the forms "Form1" and "Form2" open. "Form1" is the First tabbed form and "Form2" is second. And "Form1" is displayed.

    Cannot close "Form2"

    I even tried setting focus to one of the fields in "Form1" but the focus still remains on "Form2" field.

    Is it possible to switch form positions? As in Switch Tabbed order of the forms?

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2012-02-29T19:26:18+00:00

    There is probably a better way to accomplish your goal - please explain what the end result should be.

    After you open Form1, you could close Form2.

    You could use the current event of Form2 to open Form1.

    There doesn't seem to be any reason to open Form2, why not just open Form1 and skip Form2 completely?

    Was this answer helpful?

    0 comments No comments