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