Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I disable the close ( x ) button on the main MS Access Window? 1

Status
Not open for further replies.

spookster

Programmer
Apr 3, 2006
8
GB
Some of my users sometimes close the whole access whenever a report is maximized, so I want to disable the access close button whenever a report is loaded. Couldn't find out how, anywhere.
 
this is from the FAQs i think. Worked well for me.

bol
wah

(Q) I want to make sure that users always exit my database using the Exit button provided on my Switchboard. However, I'm not able to prevent them from closing Access itself. Is there a way to control how they exit Access?

(A) You can use the UnLoad event of a form to do this. If your switchboard is the first form to open and always remains open in the background, you can apply the following method on the switchboard. Otherwise, I would recommend creating a hidden form for this functionality.

Define a new variable in a new module

Public pboolCloseAccess as Boolean
'Note: Access 2.0 does NOT recognize Boolean
'type variables. Use integer type instead,
'passing a -1 as True, and 0 as False.


Now, when you open the database, set
pboolCloseAccess=False

In your (Switchboard/Hidden) Form's Unload Event, set the variable to true and also check for its value
pboolCloseAccess=True
DoCmd.Close acForm, "hfrmCloseAccess"
docmd.Quit

If your Switchboard form closes during one instance, then create a new form (hfrmCloseAccess). You can minimize the size if you want because it will be in hidden mode. Type the following in hfrmCloseAccess's OnUnload Event
if not pboolCloseAccess then cancel = true

Create the Autoexec macro. If you already have one, make sure that you open hfrmCloseAccess before anything else IN HIDDEN MODE.

The reasoning here is, when someone clicks X in Access's window, the System starts closing down all open objects in a first-open-last-close basis. Since your hfrmCloseAccess form is the first one to open, it will be the last to close. And since the boolean var is still False, Cancel will always be true, hence Access will not close. On the other hand, when the user clicks on the Exit button or closes your switchboard, you're setting the boolean var to True and then closing the hfrmCloseAccess form, which WILL close now and hence Access will close itself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top