?
Solved

halt access close if form is open

Posted on 2009-12-30
4
Medium Priority
?
289 Views
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 : http://www.mvps.org/access/general/gen0005.htm 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
0
Comment
Question by:valmatic
4 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 26149713
see this link for another way

How to disable the Close button on the Application window and the Exit command on the File menu
http://support.microsoft.com/?kbid=300688
0
 
LVL 58

Expert Comment

by:harfang
ID: 26151111
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?

(°v°)
0
 
LVL 58
ID: 26153138
<< 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.
JimD.

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

0
 
LVL 7

Author Comment

by:valmatic
ID: 26154456
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.  
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

840 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