By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,307 Members | 1,929 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,307 IT Pros & Developers. It's quick & easy.

Close Button Problem

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.
Nov 13 '05 #2

P: n/a
ni*****@aol.com (Nick250) wrote in message news:<20***************************@mb-m11.aol.com>...

In the form's properties (format) set close box to no.

Neil
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

Nov 13 '05 #3

P: n/a
NeilAnderson wrote:
ni*****@aol.com (Nick250) wrote in message
news:<20***************************@mb-m11.aol.com>...

In the form's properties (format) set close box to no.

Neil
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


That won't help with the Access window itself to which the OP was referring.
Nov 13 '05 #4

P: n/a
>
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.


Deano, thank you for your reply. Perhaps you can help me refine this. What I
am really looking for is a "setting" or snipit of code that simply disables the
Access close button from the git go. The user never sees it, or if it is
visible, clicking on it would do nothing. (Perhaps a message box that says
"This Feature Unavaible"). Something that would run on startup, or in the load
event of my main form, like:

CloseButton=False

Ideas? TIA

Nick
Nov 13 '05 #5

P: n/a
Nick

I think this is what you're looking for.

First create a new code module and paste the following ...
'*********
Option Compare Database

'The code below will do EXACTLY that for you (i.e. it will "disable
the 'X' in the actual Access window itself). I use this code in ALL my
applications.
'All you need to do is somewhere in your "startup routine" is to issue
the code line:
'EnableDisableControlBox False
'Then in YOUR application "Close function/routines", simply issue the
code line:
'EnableDisableControlBox True

Private Declare Function apiEnableMenuItem Lib "user32" Alias _
"EnableMenuItem" (ByVal hMenu As Long, ByVal wIDEnableMenuItem As
Long, _
ByVal wEnable As Long) As Long

Private Declare Function apiGetSystemMenu Lib "user32" Alias _
"GetSystemMenu" (ByVal hwnd As Long, ByVal Flag As Long) _
As Long

Function EnableDisableControlBox(bEnable As Boolean, _
Optional ByVal lhWndTarget As Long = 0) As Long

On Error GoTo ErrorHandling_Err

' ----------------------------------------------------------------------
' Purpose: Example of how to disable or enable the control box of
' a form, report, or the Access parent window.
'
' Accepts: bEnable, which determines whether to disable or enable
' the control box
'
' Also accepts lhWndTarget (which is optional), if you want
' to use a window handle other than the Access parent window.
'
' Returns: N/A
'
' Example usage: lRetVal = EnableDisableControlBox(True) to enable
-OR-
' lRetVal = EnableDisableControlBox(False) to disable
'
' NOTE: If no hWnd is passed in for a specific form, then the code
' assumes you want to enable/disable the Access parent window
' ----------------------------------------------------------------------

Const MF_BYCOMMAND = &H0&
Const MF_DISABLED = &H2&
Const MF_ENABLED = &H0&
Const MF_GRAYED = &H1&
Const SC_CLOSE = &HF060&

Dim lhWndMenu As Long
Dim lReturnVal As Long
Dim lAction As Long

lhWndMenu = apiGetSystemMenu(IIf(lhWndTarget = 0,
Application.hWndAccessApp, lhWndTarget), False)

If lhWndMenu <> 0 Then
If bEnable Then
lAction = MF_BYCOMMAND Or MF_ENABLED
Else
lAction = MF_BYCOMMAND Or MF_DISABLED Or MF_GRAYED
End If
lReturnVal = apiEnableMenuItem(lhWndMenu, SC_CLOSE, lAction)
End If

EnableDisableControlBox = lReturnVal

ErrorHandling_Err:
If Err Then
'Trap your error(s) here, if any!
End If
End Function

'--------------------
'Rob Richards
'Archery Software Solutions
'*********
Next, paste the following code into the module behind your switchboard
form ...

'*********
Private Sub Form_Close()
Dim lRetVal As Long
lRetVal = EnableDisableControlBox(True)
End Sub

Private Sub Form_Open(Cancel As Integer)
Dim lRetVal As Long
lRetVal = EnableDisableControlBox(False)
End Sub
'*********

Then "Debug | Compile" and "File | Save" the module.

If I've explained it properly, it will disable the close button in the
top right corner.

Feel free to email me directly if you have trouble.

Kind Regards

Nathan
Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.