Set focus to popup form doesn't work (1 Viewer)

ellenr

Registered User.
Local time
Today, 11:32
Joined
Apr 15, 2011
Messages
397
I have a popup form that calls a second popup for some info. When the second popup is closed, I want its close button to send the focus back to a specific control on the first popup. Vba to Forms!frmMyForm.SetFocus doesn't work. Is there a way to do this?
 

missinglinq

AWF VIP
Local time
Today, 11:32
Joined
Jun 20, 2003
Messages
6,423
If a Form has a single Textbox, Combobox or Command Button, etc. whose Enabled Property is set to Yes, it cannot receive Focus! So, instead of setting Focus to the Form, set it to the Control on the Form:

Forms!frmMyForm![ControlName].SetFocus

Linq ;0)>
 

ellenr

Registered User.
Local time
Today, 11:32
Joined
Apr 15, 2011
Messages
397
My OnClick event for the close button on the top popup form:
Code:
Private Sub done_Click()
DoCmd.Close
Forms!TimePopupNew![Combo6].SetFocus
End Sub
The code does nothing except to close the top form. There are other controls on the TimePopupNew form.
 

Minty

AWF VIP
Local time
Today, 15:32
Joined
Jul 26, 2013
Messages
10,354
If your form is opened as a popup and Modal dialog, you can set the focus after the form closes in the calling forms code, as the calling forms code is "paused" until the modal form is closed, so something like

Code:
DoCmd.OpenForm "frmYourDialog", , , ,  acDialog
[COLOR="Green"]'Do whatever happens on your form then when closed [/COLOR]
me.combo6.setfocus

Have a read of this thread that may help with your use of popups / modal forms https://access-programmers.co.uk/forums/showthread.php?t=179101
 

ellenr

Registered User.
Local time
Today, 11:32
Joined
Apr 15, 2011
Messages
397
Minty, OMG! It works! Thank you so much. I am continually amazed both by how much I don't know after all these years and by the bright, unselfish experts willing to share their expertise with the rest of us. I learn something new with every new project.
 

ellenr

Registered User.
Local time
Today, 11:32
Joined
Apr 15, 2011
Messages
397
One last question (I hope). One of my popup input forms is a form to verify timecard info previously entered. It works correctly as a popup but not when opened as dialog (which I need it to do). Sample of code line that does not work:
Code:
If ([ti1]<>[timein1]) Or ([ti1] Is Null And [timein1] Is Not Null) Or ([ti1] Is Not Null And [timein1] Is Null) then

If ti1 doesn't match the previously entered timein1 (entered by a different operator), it should make timein1 visible and instructs the user to enter the proper value. It doesn't detect an error if opened as dialog. If I leave it as a normal popup it works properly but I can't get back OnClose to the lower z popup control.
 

ellenr

Registered User.
Local time
Today, 11:32
Joined
Apr 15, 2011
Messages
397
The only way I could get it to work was to remove the "dialog" and open it as Normal but set it as a Popup, not modular. Upon opening, it sets the calling popup to visible false. When I close it, it makes the calling popup visible again and it lets me return to the proper control. I could never discern why the same code behaved differently when opened as dialog.
 

Minty

AWF VIP
Local time
Today, 15:32
Joined
Jul 26, 2013
Messages
10,354
The other thread describes some of the behaviour differences, if those controls are on another form it could be the way you are referencing them, or simply that because control has passed to the modal pop up that the underlying form hasn't saved the record.

Try a me.dirty = false before opening the popup to force a save.
 

ellenr

Registered User.
Local time
Today, 11:32
Joined
Apr 15, 2011
Messages
397
Interesting thought, but I don't see how it applies in this case, as the comparison is being made between a just entered value and a value in a table that had been entered previously. I will continue to explore out of curiosity. Will let you know if I solve it. Meantime it is working as a simple popup when I make the calling popup unvisible/visible. Thanks for the input!
 

shadow9449

Registered User.
Local time
Today, 11:32
Joined
Mar 5, 2004
Messages
1,037
If your form is opened as a popup and Modal dialog, you can set the focus after the form closes in the calling forms code, as the calling forms code is "paused" until the modal form is closed, so something like

Code:
DoCmd.OpenForm "frmYourDialog", , , ,  acDialog
[COLOR="Green"]'Do whatever happens on your form then when closed [/COLOR]
me.combo6.setfocus

Have a read of this thread that may help with your use of popups / modal forms https://access-programmers.co.uk/forums/showthread.php?t=179101

I know this is an old thread but I ran into this problem and it's now solved with your help. Thank you!
 

Users who are viewing this thread

Top Bottom