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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop Form Closing but allow whole database to close.

Status
Not open for further replies.

Prufrock

Instructor
Sep 4, 2002
77
0
0
AU
I have a form that is central to my database. Don't want to allow any way to close it (thus stopping accidental closures) except when a user clicks on a close database button.

I have the following code in the form unload which works fine.

Private Sub Form_Unload(Cancel As Integer)
If mblnCancel = False Then Cancel = -1
End Sub

However I can't close the database with this code in place. Can anyone help with the way I can have a button which would allow the database to close either still leaving the unload code in place or turning it to true to close the database.

Or any way to do this in a easier manner?
 
Goto the form's Properties - Format and set Close Button to No. Then place a button on the form with this code:

Code:
Private Sub CloseDB_Click()
 DoCmd.Quit
End Sub

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thanks for that. Will be fine up to a point. I am using Access 2007 and have tabbed forms in place for a range of reasons. Currently they can right click on the tab and select Close even if the close button is No as you suggest.

Therefore I need to ensure they can't right click close as well which is where the code I dealt with came in. If you can suggest a way to stop the right click Close approach then we have a full solution. Thanks for your help.
 
You can disable this in your Startup options.

In Access 2003 it's Tools > Startup > Allow Default Shortcut Menus.

Ed Metcalfe.

Please do not feed the trolls.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top