Disable "X" - Access 2007 (1 Viewer)

billyr

Registered User.
Local time
Today, 15:48
Joined
May 25, 2003
Messages
123
I need to disable the "X" close on the Access window with my application. I have tried 2 approaches from this forum and 1 from the knowledge base and none of them works with my application. They all seem to gray out the "X" but none disables it. I get no errors at compile or when running the app - just no desired result. There can be 2 or 3 forms open at once with my app. I do use a hidden form to hold some session specific information and I use an autoexec. Your held is appreciated as always.
 

datAdrenaline

AWF VIP
Local time
Today, 14:48
Joined
Jun 23, 2008
Messages
697
I use a much simpler approach ... Also, I wanted to point out that I don't think disabling the 'X' on the applicaiton will FORCE people to use a custom exit button of sorts since I *think* you can use keys to close the active form, and or app. (ctrl-F4 or alt-F4) ..
In order to FORCE someone to use a custom "Close" button, I CANCEL a hidden forms (use can use a form that stays open all the time too) Unload event with code like this ...

Code:
Public Sub Form_Unload(Cancel As Integer)
 
    Cancel = True
 
End Sub
Now ... the form just plain out WON'T close, thus Access won't close ....

Then in the code for the Click event of a "Close" button ... I disable the "Unload" event, then close the form ...

Code:
Public Sub btnCloseApp_Click()
 
    Forms("MyHiddenForm").OnUnload = ""
 
    ... Your code here (often I close all open forms here too) ....
 
    DoCmd.Quit acSaveNone
 
End Sub

By setting the OnUnload to a ZLS (Zero Length String), the code is still there, it is just not fired, and thus does not cancel the unload event, and thus allowing Access to close.
 

LPurvis

AWF VIP
Local time
Today, 20:48
Joined
Jun 16, 2008
Messages
1,269
No - I'm afraid I have to pick you up on that there Dallr...

The plural of Borg is "Borg". :p
 

ROMADOZ

Registered User.
Local time
Today, 14:48
Joined
May 14, 2008
Messages
31
I am not near as savvy in access, can you hook me up with a little more detailed version of how to do this from scratch? How to make the form the way it needs to be in the properties and such?
 

RuralGuy

AWF VIP
Local time
Today, 13:48
Joined
Jul 2, 2005
Messages
13,825
A great big welcome to Brent and dallr from Access World Forums. It is a delight to see you folks have found us. A great addition to the answer pool.
 

ROMADOZ

Registered User.
Local time
Today, 14:48
Joined
May 14, 2008
Messages
31
ruralguy... fancy meeting you here. In the explanation above, can you elaborate for me? I need to do exactly that, but am still in the dark as to the whole working.
 

RuralGuy

AWF VIP
Local time
Today, 13:48
Joined
Jul 2, 2005
Messages
13,825
If you are talking about the hidden form, I do that all of the time. I load my "Kick-Em-Off" form hidden with the AutoExec macro. This form serves as my housekeeping form as well and drives the rest of the system. Since it is the first form to open it will be the last form to close regardless of how the user exits (except the three finger salute). You can cancel the UnLoad event of this form and stop the application from closing unless the user has completed any sequence you want.
 

ROMADOZ

Registered User.
Local time
Today, 14:48
Joined
May 14, 2008
Messages
31
exactly, now how do I do that?

I load my "Kick-Em-Off" form hidden (How do I make a form hidden? How do I make it load on open?)
with the AutoExec macro. (How do I make the macro?)
 

RuralGuy

AWF VIP
Local time
Today, 13:48
Joined
Jul 2, 2005
Messages
13,825
In the Ribbon click the "Create" tab and then on the right you should see "Macro".
 

ROMADOZ

Registered User.
Local time
Today, 14:48
Joined
May 14, 2008
Messages
31
done... I have put the action to openform, chosen the form and changed the mode to hidden. Next?:)
 

RuralGuy

AWF VIP
Local time
Today, 13:48
Joined
Jul 2, 2005
Messages
13,825
Use this helpful kink *but* go to the "Current Database" instead of the "Trust Center". You can then set your Display Form to "(none)" instead of your SwitchBoard. You can then use the OnLoad and OnOpen events of your hidden form to load any form you want.
 

ROMADOZ

Registered User.
Local time
Today, 14:48
Joined
May 14, 2008
Messages
31
sweet, thanks... here is my code, can you tell why the ribbon is still visible?

Option Compare Database
Private Sub Form_Load()
Me.Visible = False
DoCmd.OpenForm "switchboard"
'hide the ribbon
DoCmd.ShowToolbar "Ribbon", acToolbarNo
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not boocloseaccess Then Cancel = True
End Sub
 

RuralGuy

AWF VIP
Local time
Today, 13:48
Joined
Jul 2, 2005
Messages
13,825
If this is your "hidden" form then you should not need the Me.Visible = False! Hiding the Ribbon is more complicated than you have. I believe you can replace it with a practically non existant ribbon but you can not just turn it off. Please start a new thread with this question.
 

ROMADOZ

Registered User.
Local time
Today, 14:48
Joined
May 14, 2008
Messages
31
I found a threat that had that code specifically, I posted there... it is in macros under ribbon. Can you help on that thread, I have no response in it yet. The macro works when I run it manually, but not when it runs auto on open.
 

datAdrenaline

AWF VIP
Local time
Today, 14:48
Joined
Jun 23, 2008
Messages
697
>> Hiding the Ribbon is more complicated than you have. I believe you can replace it with a practically non existant ribbon but you can not just turn it off.<<

Actually ... you can just turn it off ... you just can't have ANY ribbon AT ALL with the method shown, but it will indeed turn it, and the office button completely "off" ...
 

Users who are viewing this thread

Top Bottom