Nick250 wrote:
I have a simple app that I created for our Real Estate office using
Access 2000 and it is working fine except for on thing. I need to
keep the close button hidden from the users. No problem
accomplishing this it in forms using the forms properties. However
the close button for Access program itself is always there in the
upper right hand corner. How do I hide or disable it? I have played
around with options and startup options, looked in the help files to
no avail. Probably a pretty basic question for this forum, but your
help would be much appreciated.
Nick
I do it this way;
I declare a public variable;
Public vCloseApp As Boolean
In the Unload event of my main form, which is always open (important!), I
have this code;
------
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo err_unload
If vCloseApp = False Then
Cancel = True
End If
exit_err_load:
Exit Sub
err_unload:
MsgBox Err.Description & " " & Err.number
Resume exit_err_load
End Sub
------
In the Load event I of the form I initialise the value of vCloseApp;
------
Private Sub Form_Load()
vCloseApp = False
End Sub
------
In the Exit button on that form I have this code;
---------
Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
vCloseApp = True
Response = MsgBox("Are you sure you wish to quit the application?",
vbQuestion + vbYesNo, "Quit")
If Response = 6 Then 'i.e yes, let's quit
DoCmd.Quit
ElseIf Response = 7 Then 'i.e no, I don't want to quit the app
vCloseApp = False
Exit Sub
End If
Exit_cmdExit_Click:
Exit Sub
Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click
End Sub
-----------
Explanation;
------------
The app starts, the main form loads and vCloseApp is set to False.
If they click the Exit button like they should then I assume they want to
quit and set vCloseApp to True. However I then ask them to confirm this.
If they change their mind then it's set to False. The Unload event then
fires which checks the value of vCloseApp, if it's True then the app quits.
If someone tries to close the app using the X button the Unload event
catches this and checks the value of vCloseApp. If it's False then the event
is cancelled - the form does not unload and the app stays open. If it's
True then they've clicked the Exit button prior to the unload event firing,
all is well and the app quits.