Access 2007 - how to cancel the closing of the database?

Posted on 2011-04-27
Last Modified: 2012-06-27
Hi Experts,

I'm trying to check for a condition when a form is deactivated. If the condition is true, I really want the user to get the message before they're done with their session. The "On deactivate" event for the form fires when the user attempts to close the database. Can I use the "On deactivate" code to stop the user from closing the database if the condition is true? How would I stop the database from closing?

Question by:JC_Lives
    LVL 75

    Accepted Solution

    Use the Form Unload event, which can be cancelled:

    Private Sub Form_Unload(Cancel As Integer)
        If <YourCondition> = True Then Cancel = True
    End Sub


    Author Closing Comment

    Perfect, thank you.
    LVL 75

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)
    You are welcome ...


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
    Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
    With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now