Detect LostFocus of PopUp Form

sonic8

AWF VIP
Local time
Today, 08:38
Joined
Oct 27, 2015
Messages
1,151
Hey Access People!

How can I detect when a pop-up form "lost the focus", by which I mean when another form becomes Screen.ActiveForm?
Particularly for the scenario of the user just clicking into the main form with the mouse.

Neither the LostFocus/Decativate events of the pop-up nor the GotFocus/Activate events of the main form fire.

I would theoretically be possible to run a time or a loop and check Screen.ActiveForm. - This would be fairly ugly, I'd rather avoid that.

Is there a better way?
 
What are you actually trying to do? Why would you need to detect the pop up losing focus? There may be other events or methods to accomplish what you need. Also is the pop up closing or are you keeping multiple forms open?
 
What are you actually trying to do?
I am creating an overlay pop-up form over a control in a continuous form. This "overlay form" provides advanced editing capabilities depending on other data entered in the record of the continuous form.

Why would you need to detect the pop up losing focus?
To hide it then.
 
So the pop up is not modal and you switch back and forth from the editing popup form back to the main form without closing the popup?
 
So the pop up is not modal and you switch back and forth from the editing popup form back to the main form without closing the popup?
Exactly.
When the user clicks into the main form, I want to hide the pop-up.
 
You might try setting the recordset of the editing form to the recordset of the continuos form. They will always be on the same record and any updates in the pop up occurs to the recordset of the continuous. You may need a refresh event on returning to the main form.

How is the editing form opened and closed?
Can you share a sample db or at least give a screen shot?
 
You might try setting the recordset of the editing form to the recordset of the continuos form.
The editing form is unbound.
But even if it was bound, I don't think the record would be updated when just clicking elsewhere while the same record is still current and displayed in the editing form.

How is the editing form opened and closed?
DoCmd.OpenForm / DoCmd.Close
The form is opened (or made visible) when the users sets the focus into the textbox control that the edit form is replacing.
 
But even if it was bound, I don't think the record would be updated when just clicking elsewhere while the same record is still current and displayed in the editing form.
Well you are wrong to think that. See demo and select productlistbound. Double click to open the zoom. Make edits in the zoom box and move to another record in the main form. No need to close.
 
Are you editing multiple fields or just a single field. The bound idea works very well as per the demo I posted. I would do that if doing multiple fields. If you want to stay unbound how are you pushing current values to the pop up (or not)? Y

Wouldn't the Activate event run then?
No
The Activate event doesn't occur when a form receives focus back from a dialog box, popup, or another form.

So if you are going to hide it probably need to put that in the calling forms control's got focus
If you are planning to hide it, why not a Ok, Cancel on the pop up and just close it?

Can you show a screen shot of the popup?
 
Make edits in the zoom box and move to another record in the main form.
I didn't look at the demo. I believe you that it works that way.
When the user would move to another record in the main form, the Form_Current event would fire and also solve my problem.
However, this wasn't the question. The user might very well also click into another control of the current record.
 
If you are planning to hide it, why not a Ok, Cancel on the pop up and just close it?
Because these are additional unnecessary UI controls I want to avoid. For space and usability.
 
I updated the demo since I had no instruction on how to bring up the zoom for these controls.
 

Attachments

For clarification, I recorded a tiny video showing the intended functionality, as it works when just using [TAB] on the keyboard.
2024-07-16_16h47_38.gif

I want to achieve the very same behavior when the user clicks into the next control using the mouse.
(PS: Or any other control in the same record. I don't want to handle the GotFocus for every other control on the form, as this is error prone when new controls are added.)
 
Last edited:
I updated the demo since I had no instruction on how to bring up the zoom for these controls.
Now I looked at the demo. - It has the deficit I expected. When clicking into the same record the changes are not detected.
 
For clarification, I recorded a tiny video showing the intended functionality, as it works when just using [TAB] on the keyboard
Not helpful. I do not see a popup form. looks like you are on a continuous form and tabbing into fields. What is the point?
 
I do not see a popup form.
That is the point exactly!
You see the text box changing into two combo boxes? The text box is just a normal control on the continuous form, which is editable and used for many other record types. The two combo boxes are on the overlay edit form, which is then displayed on top of the text box.
 
Do not yell at me, because you cannot be boithered to clearly articulate your very niche approach. No one is going to guess that is what you are asking. Spend a little effort to ask a question.
I had no intention to yell at you. I'm sorry, if I created that impression by bolding the text.

I think, I asked a very precise question in the initial post:
How can I detect when a pop-up form "lost the focus", by which I mean when another form becomes Screen.ActiveForm?
Particularly for the scenario of the user just clicking into the main form with the mouse.

Why not simply capture the after update event of both those controls on the pop up in your main form?
Because the user might decide not to update any of the controls, or he might be updating one control multiple times without the intention of moving on to the next control in the underlying continuous form.
 
(PS: Or any other control in the same record. I don't want to handle the GotFocus for every other control on the form, as this is error prone when new controls are added.)
I think you might be stuck if you are planning to click out of the pop up. If you are worried about needing the GotFocus event for something else then I would build a class module to capture the got focus events. This way you do not interfere with these events. You could simply create a loop that instantiate the class and probably a collection class to hold these instances. Then when you add more controls you add in the loop. Should not be error prone.

My first attempt was to capture the change event of the controls on the pop up. Seemed to work ok. I do not think from the pop up you can capture lostfocus, deactivate, or even the after update of the pop up controls since that does not happen if you click out of the popup. Is the main form a pop up? If not at least you have a chance to use it activate.
 
How can I detect when a pop-up form "lost the focus", by which I mean when another form becomes Screen.ActiveForm?
Particularly for the scenario of the user just clicking into the main form with the mouse.
Neither the LostFocus/Decativate events of the pop-up nor the GotFocus/Activate events of the main form fire.
I would theoretically be possible to run a time or a loop and check Screen.ActiveForm. - This would be fairly ugly, I'd rather avoid that.
Is there a better way?

Hi Philipp
Unfortunately, I don't believe it is currently possible

I brought up a similar issue in the MVP NDA group at the end of March 2023
The issue I raised at the time was related to breakpoints in popup forms and still has not been fixed. See my article:

Even when a popup form is in use, it is not the Screen.ActiveForm as it is not part of the standard application window.
In fact, if another non popup form is open, that will remain the Screen.ActiveForm

For that reason, there was a suggestion of adding 2 new items: Screen.ActivePopupForm/Screen.ActivePopupControl
@shanegroff actually added that as a suggestion in the feedback portal somewhere around early April 2023
Unfortunately, I can't find it at the moment but perhaps Shane will see this and respond
 
Last edited:

Users who are viewing this thread

Back
Top Bottom