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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove the close button from Access 2000 3

Status
Not open for further replies.

Webkins

Programmer
Dec 11, 2008
118
US
Hello, I have a MSAccess 2000 form in which loads automatically when the database is opened. On this form is a "Exit Database" button which executes VBA code prior to closing the form and exiting the database. The problem is that the users are using the red "X" button in the upper right hand corner to exit and not the button I have provided. How can I disable or remove this red "X" close button from Access so that mine is the only possible way to exit. Thank you for your help.
 
In the form's properties you can set the "Close Button" to "No" which will disable it.
 
Another route, you can run or call the code from the Form_Unload event.

 
I heve disable the form close button. I need to disable or remove the MSAccess close button. Thank you
 
I'm not sure if you can close the access button but reguardless, if the form is open and someone closes down Access, the form_Unload event still fires.

From there you can still execute your vba code.

Or

in the Form_Unload Event set cancel to 1 and that should stop it.

Code:
Private Sub Form_Unload(Cancel As Integer)
Cancel = 1
MsgBox "Program Still Open"
End Sub
 
Bear in mind, setting cancel to 1 by itself will not let you shut down Access. You will need to set up code to determine if it is "OK" to close Access.
 
As well as stopping the use of the red X, I also have the following : (can't remember where I found any of this though & claim no originality on my part)

Code:
Call ExitMenuState(false)

'Disable the Menu Option
Sub ExitMenuState(blnExitState As Boolean)
    Application.CommandBars("File").Controls("Exit").Enabled = blnExitState
End Sub

This stops them right clicking the command bar & then close

Then, for good measure, I'm also disabling F4

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'This disables F4 so that app cannot be stopped by pressing Alt-F4 or form closed with ctl-F4
If KeyCode = 115 Then KeyCode = 0

End Sub

There's other ways too - such as putting something in the form_unload event, that stops the form closing unless they've clicked on your exit button.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top