Close Form Pop-up if it lost focus

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MsAccess2007
    New Member
    • Jul 2014
    • 1

    Close Form Pop-up if it lost focus

    Can't get around that one! :(
    I have a few scenarios where the pop up form belongs to the record on the other main form underneath it. In a few cases, some users forget to close the pop-up and navigate to another record on the main form. Now when that happens, the other forgotten to be closed pop-up would still be opened in the background and once its button is clicked, the user thinks it belongs to the new record when it does not.

    Is there a way through VBA to make sure that when a certain pop-up form loses the main focus, it closes exactly as close form command?

    Thank you very much for the help.
  • JustJim
    Recognized Expert Contributor
    • May 2007
    • 407

    #2
    It's always tricky to get VBA to do 'destructive' things to the item that contains that code. There are two things you could do.

    First would be to make the secondary form Modal so that it has to be dealt with before the user goes back to the original form.

    The second would be to have code on the original form, perhaps in its On Activate event that closes the second form, for example.

    Code:
    Private Sub Form_Activate()
    DoCmd.Close acForm, "SecondaryForm", acSaveYes
    End Sub
    You would have to think through the work-flow of the user to make sure that is what they would want/expect to happen though. This may even necessitate a MsgBox asking them if that's what they want.

    Regards,

    Comment

    • twinnyfo
      Recognized Expert Moderator Specialist
      • Nov 2011
      • 3653

      #3
      I am with Jim's first recommendation. If you have a pop-up form, you should never (ever) allow the user to be able to navigate away from that pop-up until the user has dealt with it. His solution is easy, and probably the best way to handle it. I use it all the time.

      Comment

      Working...