Proper focusing of windows in MS Access (natively or by a code)

Trigger the code from the popup form and you will get it correctly.
Yes, that's what I'm doing with my example using the Screen.ActiveForm code to determine the calling form
As already stated, that is working for both standard and popup forms when the code runs from the form
 
It seems that you've been struggling, but I doubt the only way to do it is sending a key combination. There must be something else going on, which is why I'm asking for your code, but a reproducible example would be best.


I'm not sure what you mean


I'm getting a different behavior than the one described by Colin. Read post #14, I'm getting the active form correctly every time, the only variation occurs when I switch to the code window.


I insist, there must be something else going on. I could tell you what it is if you post a file.

Thanks for your devotion to help, but there is no need for file posting. I tested what guys told me, and it's true, if you do not use tabs and instead use just overlapping windows, and no popups, this problem doesn't exist at all. In my case I then have some other problems with navigation form and some other things :). But there is no need to bother anyone here about that.

As Pat said above:
Access doesn't "see" popups. Therefore it brings you to what it does "see".

I'll just continue with what I already have (because it works) 🤷‍♂️
 
Access doesn't "see" popups. Therefore it brings you to what it does "see".
That verbiage is incorrect IMO, as other have already shown. The issue is not that access does not "see" it, it is simply because it is not the active form.

Access sees the Pop up as the active form when it is the active form. So when it has focus it is the active form.
But if you call the code from VBE, from a Menu, from another form it loses focus and no longer an active form.
This is easily demonstrated. Call a pop up and then try to launch code from anywhere (except the form) that closes the active form. The act of trying to run the code will force the form to lose focus and no longer be active. You can usually see it lose focus.
But from the form itself run.
DoCmd.Close acForm, Screen.ActiveForm.Name
and it will close. Not because "Access Sees" or "Access does not See", but because it is in fact the active form at the time code executes.
 
Here is a better test where you can close a popup by using ActiveForm
Have a tabbed form such as navigation form.
Set the timer interval to 0
Pop open a pop up form.
Have the calling form close it after a period of time.

Code:
Private Sub Command0_Click()
  DoCmd.OpenForm "form2_Popup"
  Me.TimerInterval = 3000
  loadList
End Sub

Private Sub Form_Timer()
  DoCmd.Close acForm, Screen.ActiveForm.Name
End Sub

This act of calling the code does not force the pop up to lose being the active form.
 

Users who are viewing this thread

Back
Top Bottom