472,122 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

How to SetFocus on an Opened Form?

124 100+
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:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "f_Families"
  2. DoCmd.OpenForm "f_GiftProcessing"
  3. DoCmd.OpenForm "f_Reports"
  4. DoCmd.OpenForm "f_SysMaintenance"
  5. 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_SysMaintenance form. I've tried adding a line of code after I close f_Login using all these different variations but none work:

Expand|Select|Wrap|Line Numbers
  1. Forms!f_Families.SetFocus
  2. Forms!f_Families.Form.SetFocus
  3. 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!
Jan 19 '11 #1
5 35596
375 Expert 256MB
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.
Jan 19 '11 #2
12,516 Expert Mod 8TB
Or... Just open the form you want focus on last.
Jan 19 '11 #3
124 100+
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?
Jan 19 '11 #4
375 Expert 256MB
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?
Jan 19 '11 #5
124 100+
Yes, I used my own control name (e.g. Forms!f_Families.cboChurch.SetFocus). 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.

Attached Files
File Type: zip Open Form Test.zip (845.4 KB, 768 views)
Jan 20 '11 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by a s i l b a . p t | last post: by
8 posts views Thread by Susan Bricker | last post: by
3 posts views Thread by HooHa | last post: by
1 post views Thread by anthony | last post: by
6 posts views Thread by =?Utf-8?B?VG9tYXM=?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.