473,414 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Close Button Problem

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
5 3063
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
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
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
>
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: moose | last post by:
OK Popup window? No problem PDF in popup? No problem But what about a couple of Close Window buttons? Imagine a "Close Window" button at the top of the popup page. Then the PDF which can...
1
by: dibyendu_k | last post by:
Hi, There is a problem i cant solve regarding Internet Explorer 5.5. It is regarding the Print Dialog Box. From a webpage if I open a popup window (window.open()) containing buttons Print and...
1
by: Ebrahim | last post by:
This message is in reply to a prev 1 . My application refues to close . Some one had suggested that I might have threads running.. but i solved that problem too . The app still refuses to close...
4
by: Hitesh | last post by:
Hi, I am opening an Modal dialog box using the window.Showmodaldialogbox(), and in that window i am having an aspx form with say one ASP.NET Button control. i am doing some operation on the...
2
by: Bruce Wiebe | last post by:
hi all im having a problem accessing a text file on my hard disk after ive created it and added some text to it it would appear that the file is still locked. What happens is this i have...
2
by: Del | last post by:
I have a popup form that consist of a single field called EnteredBy and a Subform that has three fields. The popup form also has a button in the Form Footer called close. In the On Click event I...
1
by: somtabu | last post by:
hello, i have a problem in vb.net windows application, verson is 2005 and framework is 2.0 I want to close a form by using the close button which is right hand top side of the window. i want,...
2
by: Bruce | last post by:
Hello, I have a form in an Access 2003 application which opens maximized. Its CloseButton property is set to false. On this form I have a command button that opens a report in preview mode. ...
5
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.