View Full Version : Disable "X" - Access 2007


billyr
06-22-2008, 04:15 AM
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.

ajetrumpet
06-23-2008, 10:46 AM
I wonder if this article would work for 2007 as well???

http://support.microsoft.com/kb/245746

dallr
06-23-2008, 06:55 PM
This should do the trick, the previous link does not work in 2007
http://www.utteraccess.com/forums/showflat.php?Cat=&Board=48&Number=1658279&page=0&view=expanded&sb=5&o=31&fpart=1

datAdrenaline
06-24-2008, 12:02 AM
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 ...


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 ...


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.

dallr
06-24-2008, 04:35 AM
Brent like you and Leigh planned an attack to simultaneously take over this forum and assimilate us.. http://www.access-programmers.co.uk/forums/showthread.php?p=718181#post718181

You Borg's (http://en.wikipedia.org/wiki/Borg_%28fictional_aliens%29) you!! :D

PS: Or is it you just like to follow me around.

dallr

LPurvis
06-24-2008, 04:47 AM
No - I'm afraid I have to pick you up on that there Dallr...

The plural of Borg is "Borg". :-p

ROMADOZ
06-24-2008, 07:34 AM
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
06-24-2008, 07:39 AM
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
06-24-2008, 07:43 AM
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
06-24-2008, 07:51 AM
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
06-24-2008, 07:57 AM
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
06-24-2008, 08:04 AM
What version of Access are you using?

ROMADOZ
06-24-2008, 08:05 AM
Access 2007. I already have a new form made.

RuralGuy
06-24-2008, 08:13 AM
In the Ribbon click the "Create" tab and then on the right you should see "Macro".

ROMADOZ
06-24-2008, 08:17 AM
done... I have put the action to openform, chosen the form and changed the mode to hidden. Next?:)

RuralGuy
06-24-2008, 09:58 AM
Use this helpful kink (http://www.btabdevelopment.com/main/QuickTutorials/A2K7Howtoenablecodeandmacros/tabid/57/Default.aspx) *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
06-24-2008, 10:37 AM
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
06-24-2008, 10:47 AM
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
06-24-2008, 01:30 PM
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
06-24-2008, 06:53 PM
>> 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" ...

RuralGuy
06-24-2008, 07:43 PM
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" ...So I discovered Brent. Thanks for the code.

datAdrenaline
06-24-2008, 08:04 PM
NP Allan! ... Just after I posted ... I saw your post on the other thread I participated in with similar code ... I had intended to delete my reply ... but got side tracked, sometimes that happens me ... I blame it on the kids, but the apple doesn't fall far from the tree!! ... :D

dallr
06-27-2008, 04:17 AM
Allan
It is good to be here, I would definitely pop in from time to time and lend a hand.

Leigh
"the plural of Borg is Borg".....You see why i need assimilating LOL

Dallr

datAdrenaline
06-27-2008, 05:01 AM
Now, view the properties of the form and find the On Close event, then click on the three dots to the right of the property and choose "Code Builder" if/when asked ... then the code labeled Private Sub Form_Close() can be entered in the procedure "stub" that is created by Access ....

Next ... open the form used to hold the "Close Application" button and view the properties of the button and find the On Click event ... the click the three dots ... Code Builder .. enter code ...

Hope that helps!!