Cannot SetFocus back to main form


T

Tok

I'm trying to open a pop-up form from my main form only for display purposes.
The trouble is, when the popup form opens I cannot seem to setfocus back to
the main form in VB. It works when I manually click back on the main form in
normal view.

I tried using the "OnLostFocus" event for the main form, but it never even
fires when the popup window opens and grabs the focus.

Here's the code I'm trying from my main form's button named "TogglePopUp":

Private Sub TogglePopUp_Click()

If IsLoaded("frm PopUp") Then
DoCmd.Close acForm, "frm PopUp"
Else
DoCmd.OpenForm "frm PopUp", acNormal
End If

Me.Textbox1.SetFocus

End Sub

I was thinking the code was executing too fast and that the main form hadn't
lost the focus yet before the popup window opened. So I had put a huge For
Next loop just before the "Me.Textbox1.SetFocus" line as a test to delay it's
execution, but that still didn't work.

Any help would be appreciated! Thanks.
 
Ad

Advertisements

B

boblarson

If you always want the focus to be on Textbox1 when you open that other form,
why not put the focus in the On Load event of the [frm Popup] form?

Forms!YourOriginalFormNameHere.Textbox1.SetFocus

(I would give your objects meaningful names instead of Textbox1, etc. so it
is easier in code to identify what they actually are. Plus I would not use
embedded spaces in object or field names as it will simplify things for you
as you won't need brackets around things quite so much, etc.)
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________
 
T

Tok

Bob, thanks for the quick reply. I should have mentioned I tried that. I
put the following code in the OnLoad event of the popup form:

Private Sub Form_Load()

Forms![frm main]!Textbox1.SetFocus

End Sub

The code executes without an error, but the popup window still retains the
focus. I'm stumped!

boblarson said:
If you always want the focus to be on Textbox1 when you open that other form,
why not put the focus in the On Load event of the [frm Popup] form?

Forms!YourOriginalFormNameHere.Textbox1.SetFocus

(I would give your objects meaningful names instead of Textbox1, etc. so it
is easier in code to identify what they actually are. Plus I would not use
embedded spaces in object or field names as it will simplify things for you
as you won't need brackets around things quite so much, etc.)
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________


Tok said:
I'm trying to open a pop-up form from my main form only for display purposes.
The trouble is, when the popup form opens I cannot seem to setfocus back to
the main form in VB. It works when I manually click back on the main form in
normal view.

I tried using the "OnLostFocus" event for the main form, but it never even
fires when the popup window opens and grabs the focus.

Here's the code I'm trying from my main form's button named "TogglePopUp":

Private Sub TogglePopUp_Click()

If IsLoaded("frm PopUp") Then
DoCmd.Close acForm, "frm PopUp"
Else
DoCmd.OpenForm "frm PopUp", acNormal
End If

Me.Textbox1.SetFocus

End Sub

I was thinking the code was executing too fast and that the main form hadn't
lost the focus yet before the popup window opened. So I had put a huge For
Next loop just before the "Me.Textbox1.SetFocus" line as a test to delay it's
execution, but that still didn't work.

Any help would be appreciated! Thanks.
 
B

boblarson

Go into the "popup" form in Design view and look to see if its POPUP property
is set to YES. If so, change it to NO.
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________


Tok said:
Bob, thanks for the quick reply. I should have mentioned I tried that. I
put the following code in the OnLoad event of the popup form:

Private Sub Form_Load()

Forms![frm main]!Textbox1.SetFocus

End Sub

The code executes without an error, but the popup window still retains the
focus. I'm stumped!

boblarson said:
If you always want the focus to be on Textbox1 when you open that other form,
why not put the focus in the On Load event of the [frm Popup] form?

Forms!YourOriginalFormNameHere.Textbox1.SetFocus

(I would give your objects meaningful names instead of Textbox1, etc. so it
is easier in code to identify what they actually are. Plus I would not use
embedded spaces in object or field names as it will simplify things for you
as you won't need brackets around things quite so much, etc.)
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________


Tok said:
I'm trying to open a pop-up form from my main form only for display purposes.
The trouble is, when the popup form opens I cannot seem to setfocus back to
the main form in VB. It works when I manually click back on the main form in
normal view.

I tried using the "OnLostFocus" event for the main form, but it never even
fires when the popup window opens and grabs the focus.

Here's the code I'm trying from my main form's button named "TogglePopUp":

Private Sub TogglePopUp_Click()

If IsLoaded("frm PopUp") Then
DoCmd.Close acForm, "frm PopUp"
Else
DoCmd.OpenForm "frm PopUp", acNormal
End If

Me.Textbox1.SetFocus

End Sub

I was thinking the code was executing too fast and that the main form hadn't
lost the focus yet before the popup window opened. So I had put a huge For
Next loop just before the "Me.Textbox1.SetFocus" line as a test to delay it's
execution, but that still didn't work.

Any help would be appreciated! Thanks.
 
T

Tok

Yes, the popup form has the PopUp property set to YES. I need it to be a
popup form so it can stay visible over the main form. If I change it to
"NO", it creates a full view form obstructing the main form.

boblarson said:
Go into the "popup" form in Design view and look to see if its POPUP property
is set to YES. If so, change it to NO.
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________


Tok said:
Bob, thanks for the quick reply. I should have mentioned I tried that. I
put the following code in the OnLoad event of the popup form:

Private Sub Form_Load()

Forms![frm main]!Textbox1.SetFocus

End Sub

The code executes without an error, but the popup window still retains the
focus. I'm stumped!

boblarson said:
If you always want the focus to be on Textbox1 when you open that other form,
why not put the focus in the On Load event of the [frm Popup] form?

Forms!YourOriginalFormNameHere.Textbox1.SetFocus

(I would give your objects meaningful names instead of Textbox1, etc. so it
is easier in code to identify what they actually are. Plus I would not use
embedded spaces in object or field names as it will simplify things for you
as you won't need brackets around things quite so much, etc.)
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________


:

I'm trying to open a pop-up form from my main form only for display purposes.
The trouble is, when the popup form opens I cannot seem to setfocus back to
the main form in VB. It works when I manually click back on the main form in
normal view.

I tried using the "OnLostFocus" event for the main form, but it never even
fires when the popup window opens and grabs the focus.

Here's the code I'm trying from my main form's button named "TogglePopUp":

Private Sub TogglePopUp_Click()

If IsLoaded("frm PopUp") Then
DoCmd.Close acForm, "frm PopUp"
Else
DoCmd.OpenForm "frm PopUp", acNormal
End If

Me.Textbox1.SetFocus

End Sub

I was thinking the code was executing too fast and that the main form hadn't
lost the focus yet before the popup window opened. So I had put a huge For
Next loop just before the "Me.Textbox1.SetFocus" line as a test to delay it's
execution, but that still didn't work.

Any help would be appreciated! Thanks.
 
B

boblarson

You can have it one way or the other, not both I'm afraid.
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________


Tok said:
Yes, the popup form has the PopUp property set to YES. I need it to be a
popup form so it can stay visible over the main form. If I change it to
"NO", it creates a full view form obstructing the main form.

boblarson said:
Go into the "popup" form in Design view and look to see if its POPUP property
is set to YES. If so, change it to NO.
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________


Tok said:
Bob, thanks for the quick reply. I should have mentioned I tried that. I
put the following code in the OnLoad event of the popup form:

Private Sub Form_Load()

Forms![frm main]!Textbox1.SetFocus

End Sub

The code executes without an error, but the popup window still retains the
focus. I'm stumped!

:

If you always want the focus to be on Textbox1 when you open that other form,
why not put the focus in the On Load event of the [frm Popup] form?

Forms!YourOriginalFormNameHere.Textbox1.SetFocus

(I would give your objects meaningful names instead of Textbox1, etc. so it
is easier in code to identify what they actually are. Plus I would not use
embedded spaces in object or field names as it will simplify things for you
as you won't need brackets around things quite so much, etc.)
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________


:

I'm trying to open a pop-up form from my main form only for display purposes.
The trouble is, when the popup form opens I cannot seem to setfocus back to
the main form in VB. It works when I manually click back on the main form in
normal view.

I tried using the "OnLostFocus" event for the main form, but it never even
fires when the popup window opens and grabs the focus.

Here's the code I'm trying from my main form's button named "TogglePopUp":

Private Sub TogglePopUp_Click()

If IsLoaded("frm PopUp") Then
DoCmd.Close acForm, "frm PopUp"
Else
DoCmd.OpenForm "frm PopUp", acNormal
End If

Me.Textbox1.SetFocus

End Sub

I was thinking the code was executing too fast and that the main form hadn't
lost the focus yet before the popup window opened. So I had put a huge For
Next loop just before the "Me.Textbox1.SetFocus" line as a test to delay it's
execution, but that still didn't work.

Any help would be appreciated! Thanks.
 
Ad

Advertisements

T

Tok

ah, the ol' case of not having my cake and eating it too.

I guess for now I'll just suffer with manually clicking back on the main
form after the popup window opens. It's not that big a deal I suppose, just
an extra click to get the main form to activate. But I was hoping to simply
do this programatically.

I apprecaite the feedback!

boblarson said:
You can have it one way or the other, not both I'm afraid.
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________


Tok said:
Yes, the popup form has the PopUp property set to YES. I need it to be a
popup form so it can stay visible over the main form. If I change it to
"NO", it creates a full view form obstructing the main form.

boblarson said:
Go into the "popup" form in Design view and look to see if its POPUP property
is set to YES. If so, change it to NO.
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________


:

Bob, thanks for the quick reply. I should have mentioned I tried that. I
put the following code in the OnLoad event of the popup form:

Private Sub Form_Load()

Forms![frm main]!Textbox1.SetFocus

End Sub

The code executes without an error, but the popup window still retains the
focus. I'm stumped!

:

If you always want the focus to be on Textbox1 when you open that other form,
why not put the focus in the On Load event of the [frm Popup] form?

Forms!YourOriginalFormNameHere.Textbox1.SetFocus

(I would give your objects meaningful names instead of Textbox1, etc. so it
is easier in code to identify what they actually are. Plus I would not use
embedded spaces in object or field names as it will simplify things for you
as you won't need brackets around things quite so much, etc.)
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________


:

I'm trying to open a pop-up form from my main form only for display purposes.
The trouble is, when the popup form opens I cannot seem to setfocus back to
the main form in VB. It works when I manually click back on the main form in
normal view.

I tried using the "OnLostFocus" event for the main form, but it never even
fires when the popup window opens and grabs the focus.

Here's the code I'm trying from my main form's button named "TogglePopUp":

Private Sub TogglePopUp_Click()

If IsLoaded("frm PopUp") Then
DoCmd.Close acForm, "frm PopUp"
Else
DoCmd.OpenForm "frm PopUp", acNormal
End If

Me.Textbox1.SetFocus

End Sub

I was thinking the code was executing too fast and that the main form hadn't
lost the focus yet before the popup window opened. So I had put a huge For
Next loop just before the "Me.Textbox1.SetFocus" line as a test to delay it's
execution, but that still didn't work.

Any help would be appreciated! Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top