Disable close button for current database (1 Viewer)

Gismo

Registered User.
Local time
Today, 23:36
Joined
Jun 12, 2017
Messages
1,298
Hi,

How do I disable the close button for the current data base in the options setup?
 

isladogs

MVP / VIP
Local time
Today, 21:36
Joined
Jan 14, 2017
Messages
18,209
You need to load a custom ribbon that disables selected parts of the File menu at startup. CARE needed with modifications of this type or you may lock yourself out!

Do you just want to remove the 'Close Database' item or other File menu items as well?
 

Gismo

Registered User.
Local time
Today, 23:36
Joined
Jun 12, 2017
Messages
1,298
I have already created my ribbon, i only want to disable all the close button on all the forms in this database
 

isladogs

MVP / VIP
Local time
Today, 21:36
Joined
Jan 14, 2017
Messages
18,209
That's a different question entirely.
You originally asked about removing the Close Database 'button'

The Close button on a form closes that form ONLY
To do so, do ONE of the following in form properties:
1. Close Button = No. You may also want to set Control Box = No
2. Border Style = No

AFAIK there is no setting to do that globally for all forms at once in Access Options
However you could probably write code to loop through each form in turn and do that if you have a large number of forms

If you do this, make sure you include your own Close button on each form
 

jleach

Registered User.
Local time
Today, 16:36
Joined
Jan 4, 2012
Messages
308
As a side note, there's also the standard windows Close button at the top right of the Access window itself, which (AFIAK) can't be altered with the Ribbon.

There is some Windows API code that can be used to disable the button, but I tend to think it's a bit of a hack myself (changing the core UI things that people expect across every application doesn't usually do anyone any favors).

I won't bother to dig up the API code to do it as you don't seem to need it, but future readers may be interested to know and can probably find it with a little google-fu easily enough (or post back and someone will dig it up, probably in Stephen Lebans' or Dev Ashish's old codebanks).

Also - didn't the MS Access team add an Application Close event a year or two back? I seem to recall something along the lines, but not sure details offhand (ideally, this would let you do a little bit of cleanup prior to app close, because otherwise the only way was with a hidden form on startup, catching that close event, at which point Access is already half-shut down anyway - it's pretty messy). On a somewhat related note, I wrote an article about the weirdness of form events: Close, and Dirty, specifically: http://www.utteraccess.com/wiki/Form_Event_Quirks

Cheers
 

MarkK

bit cruncher
Local time
Today, 13:36
Joined
Mar 17, 2004
Messages
8,179
You can stop the database from closing by cancelling the unload event of an open, even if hidden, form.
Here's sample code that only allows a form to close under certain conditions...
Code:
Private Sub Form_Unload(Cancel As Integer)
[COLOR="Green"]'   only allow this form, and the app that hosts it,
'   to close between 11am and noon
[/COLOR]    Cancel = Hour(Time) = 11
End Sub
Mark
 

Users who are viewing this thread

Top Bottom