How to SetFocus on an Opened Form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bullfrog83
    New Member
    • Apr 2010
    • 124

    How to SetFocus on an Opened Form?

    I have a login form. If a user enters the correct username and password I want to open certain forms and close the login form (among other things) when the Sign In button is clicked. I have this code in the cmdSignIn_Click () event:

    Code:
    DoCmd.OpenForm "f_Families"
    DoCmd.OpenForm "f_GiftProcessing"
    DoCmd.OpenForm "f_Reports"
    DoCmd.OpenForm "f_SysMaintenance"
    DoCmd.Close acForm, "f_Login"
    However, what I want to have happen is after the login form is closed I want to set the focus to the f_Families form, the first form that was opened. Right now, the focus goes to the f_SysMaintenanc e form. I've tried adding a line of code after I close f_Login using all these different variations but none work:

    Code:
    Forms!f_Families.SetFocus
    Forms!f_Families.Form.SetFocus
    DoCmd.SelectObject acForm, "f_Families"
    You'd think this would be a simple task but no matter what I try, the focus always goes to the last form opened in my code. How do I do this? Thanks!
  • RuralGuy
    Recognized Expert Contributor
    • Oct 2006
    • 375

    #2
    Set your focus to a control on the form you want to have the focus. I'm surprised you want so many forms open at once.
    Forms!f_Familie s.ControlName.S etFocus

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Or... Just open the form you want focus on last.

      Comment

      • bullfrog83
        New Member
        • Apr 2010
        • 124

        #4
        That doesn't work. The reason I want so many forms open is because I have my forms open as tabbed documents with the documents tab displayed so when the user logs in, he can easily tab between the four main forms now open. I could open my f_Families form last (and I thought of that) but I want the tabs to be in a specific order. Is there another way to get at what I want?

        Comment

        • RuralGuy
          Recognized Expert Contributor
          • Oct 2006
          • 375

          #5
          You are saying that the SetFocus code I supplied does *not* work? You used your ControlName, right? Something else is going on. Can you post your db, or at least enough of a sample so that we can test this?

          Comment

          • bullfrog83
            New Member
            • Apr 2010
            • 124

            #6
            Yes, I used my own control name (e.g. Forms!f_Familie s.cboChurch.Set Focus). I've attached my db. Again, the code is triggered on the OnClick event of the Sign In command button on my f_Login form. To test the code, use these credentials on the login form:

            username = michele
            password = shelly

            She is the only user set up.

            Thanks!
            Attached Files
            Last edited by bullfrog83; Jan 20 '11, 02:59 PM. Reason: typo

            Comment

            Working...