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!

No exit buttons on Application Bar or Form bar 5

Status
Not open for further replies.

DanAuber

IS-IT--Management
Apr 28, 2000
255
0
0
FR
I have a form that is started up via the autoexec macro. There is a button on the form that people use to exit. I want to 'force' people to exit with the button by removing all other possibilities - i.e. removing both the X on the Form in the top right hand corner, and also removing the X from the Access application Bar. This way - the only way to shut down would be to use my button.<br>I have sorted the form by removing exit buttons. I have also created a blank toolbar and a blank menubar - but I can't get rid of the Close button (X) on the access application bar. <br><br>Any help gratefully received <p>Dan Auber<br><a href=mailto:DanAuber@aol.com>DanAuber@aol.com</a><br><a href= Auber's Home Page</a><br>
 
You want to set the control box to &quot;No&quot; on the forms properties. Dont forget to set min max buttons to &quot;No&quot; on the forms properties.

Hope this helps.

Neemi
 
neeni's answer will get rid of the close button on the form but the close button on the Access window is not so easy. You have to use an API call.

I found this code in a thread in this forum but it did not work so I modified it. This works perfectly for me.

Put this in the Declaration section of a module
----------------------------------------------------------
Declare Function GetSystemMenu Lib &quot;user32&quot; (ByVal Hwnd _ As Long, ByVal bRevert As Long) As Long

Declare Function RemoveMenu Lib &quot;user32&quot; (ByVal hMenu As _ Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long

Global Const MF_BYPOSITION = &H400
----------------------------------------------------------

Put this sub in the same module.
----------------------------------------------------------
Public Sub Hide_CloseButton(Hwnd As Long)
On Error Resume Next

Dim SystemMenu As Long, Res As Long
SystemMenu = GetSystemMenu(Hwnd, 0)
Res = RemoveMenu(SystemMenu, 6, MF_BYPOSITION)

End Sub
----------------------------------------------------------

Put this in the Form_Load event of your startup form.
----------------------------------------------------------
Hide_CloseButton (Application.hWndAccessApp)
----------------------------------------------------------

You will still be able to see the X button but it will be disabled.

I hope this helps,
Dermot
 
Hey Dermot,

What version of access does this apply to? Does it apply to 97 and 2000 etc..

I'm gonna try your suggestion cause I wouldnt have had a clue as how to have done that.

Cheers.

neemi
 
neemi,

Iam using Access 2000 but it should work fine in 97 also, but I have not tried it.

Good luck

Dermot
 
Laois-
You really should make that an FAQ. I tried it and it worked great. Thanks.
 
I wish I could take credit for thinking of a simple solution like this, but I can't since I came across this in my reading. Although the above may work, here is a KISS way to do what you want regardless of toolbars, menubars, etc. are showing.

1. Declare a Public var such as Dim AllowClose As Boolean

2. In the On Load event on your form, set AllowClose = False

3. In the Click or DoubleClick event on your Exit command
button, set AllowClose = True and do a DoCmd.Close which
which will close the form

4. In the On Unload event on your form notice there is a
parameter Cancel - Set Cancel = Not AllowClose

The reason this works is because the Unload event (as opposed to the Close event) passes the Cancel parameter. If cancel is set to true, then the form cannot be unloaded no matter what keys are pressed or buttons are clicked. That's why you don't have to worry about closing off of a menu or toolbar. It doesn't matter. If AllowClose = False then Cancel will be true and the form will NOT unload.

Events that pass the cancel parameter come in handy. Other examples for form controls include before update and on exit. If you set cancel to true, the control cannot lose focus no matter what the user did. If you want to restore the original value, put controlname.undo somewhere in the validation code before you cancel.

Have a great night all, it's been a long day!

 
SBendBuckeye has a good approach here (I've seen this in the Getz, Litwin Access books, which no one should be without...).

The thing that this covers is the ALT + F4 close which some users will know; using ALT F4 will close the current window, which applies to the form with focus.

Closing Access itself can't be trapped.
 
Quehay,

This will trap and stop the closing of Access itself as well. That is also where I read about it and you are correct, I don't know how I would live without them.

Have a great day!
 
Hey SBB thank you for correcting--that's a good thing to know (that you can trap the app.quit)!
 
Thanks to SBendBuckeye for a great/simple solution!

But question for everyone else that has used this solution....

Bug??
If you click on the Access (x) close button FIRST (it won't close the app) BUT if you then try to exit with the command button does the form close?? Mine won't.

But if I click the Form/MenuBar (x) close button FIRST and then try to exit with the command button the form closes fine.

But I don't get an error? It just won't close if I click the Access close button first....

Hmmmm.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top