halt access close if form is open

Posted on 2009-12-30
Last Modified: 2013-11-29
Hi.  I have a number of access 2000 databases with a number of forms that rely on a button click event to run various code and then close the form.  I'm having an issue with my users taking shortcuts and closing access using the "Program"  min/max/close button instead of closing each form properly.  I do have the forms themselves locked down but can't find a good way to lock the program close "X".  I did find this : but it only halts at the last open form, rather than the 1st open form.  Any ideas how to either lock this down or halt access closing at the first open form?  thanks
Question by:valmatic
    LVL 119

    Accepted Solution

    see this link for another way

    How to disable the Close button on the Application window and the Exit command on the File menu
    LVL 58

    Expert Comment

    In my opinion, users should be allowed to close any application when they choose. Perhaps you can add an "emergency shutdown" mode when your forms are being closed from "outside", i.e. not by using the official [Close] button? Or does your application absolutely require user interaction to close forms?

    LVL 56

    Expert Comment

    by:Jim Dettman (Microsoft MVP/ EE MVE)
    << I do have the forms themselves locked down but can't find a good way to lock the program close "X". >>
    Another technique is to open a hidden form first at startup and in that forms OnUnload event, check for some type of flag that your application has set that it's OK to close.  If the flag is not set, then you cancel the unload and message the user.
     Since it's the first form open, it's the first Access attempts to close.
    See code below.

    Private Sub Form_Unload(Cancel As Integer)
              ' A close was started - need to wait until menu says its OK to close.
    10        If Not (Me![cbxOKtoclose]) Then
    20          gstrMBTitle = "Close error."
    30          gstrMBMsg = "You cannot close the application by closing the main Access window."
    40          gstrMBMsg = gstrMBMsg & Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10) & "Please close the application normally to exit."
    50          gintMBDef = vbCritical + vbOKOnly
    60          gintMBBeep = True
    70          gintMBLog = False
    80          Call DisplayMsgBox
    90          Cancel = True
    100       End If
    End Sub

    Open in new window

    LVL 7

    Author Comment

    Yeah, most of my databases rely on the user hitting a close button to finish processing on the forms.  In hindsight, not the best idea :P
    Thanks Cap, that write-up worked great.  I added a line to also gray out the close option on the file menu as well.  Now on open the switchboard loads and calls out the SetEnabledState function so the users are forced to properly close out to exit the app..  I think I'll also have write into my switchboard exit that it can't run if specific forms are still open.  

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
    I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

    759 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

    14 Experts available now in Live!

    Get 1:1 Help Now