PC Review


Reply
Thread Tools Rate Thread

Disable Application Close Button in Access 2003

 
 
KenR
Guest
Posts: n/a
 
      5th Sep 2008
I need to force users to exit using the button I provided, as several
housekeeping chores get bypassed if users exit using the "X" button in the
upper right corner of the application window. How do I disable this button?

I saw a previous post:

*******************
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, _
ByVal bRevert As Long) As Long

'Disable/Enable the Close Button Option
Public Sub CloseButtonState(boolClose As Boolean)
Dim hWnd As Long
Dim wFlags As Long
Dim hMenu As Long
Dim Result As Long

hWnd = Application.hWndAccessApp
hMenu = GetSystemMenu(hWnd, 0)
If Not boolClose Then
wFlags = MF_BYCOMMAND Or MF_GRAYED
Else
wFlags = MF_BYCOMMAND And Not MF_GRAYED
End If

Result = EnableMenuItem(hMenu, SC_CLOSE, wFlags)
End Sub

Then in your code, maybe in a splash form:
Call CloseButtonState(False) 'Disables X
Call CloseButtonState(True) 'Enables X
***********************

but I get a "Variable not Defined" error when it is called. Where are the
variables MF_BYCOMMAND and MF_GRAYED declared?

Thanks for any help...

 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      5th Sep 2008
"KenR" <(E-Mail Removed)> wrote in message
news:346575E1-E322-456B-98B1-(E-Mail Removed)...
>I need to force users to exit using the button I provided, as several
> housekeeping chores get bypassed if users exit using the "X" button in the
> upper right corner of the application window. How do I disable this
> button?
>
> I saw a previous post:
>
> *******************
> Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, _
> ByVal bRevert As Long) As Long
>
> 'Disable/Enable the Close Button Option
> Public Sub CloseButtonState(boolClose As Boolean)
> Dim hWnd As Long
> Dim wFlags As Long
> Dim hMenu As Long
> Dim Result As Long
>
> hWnd = Application.hWndAccessApp
> hMenu = GetSystemMenu(hWnd, 0)
> If Not boolClose Then
> wFlags = MF_BYCOMMAND Or MF_GRAYED
> Else
> wFlags = MF_BYCOMMAND And Not MF_GRAYED
> End If
>
> Result = EnableMenuItem(hMenu, SC_CLOSE, wFlags)
> End Sub
>
> Then in your code, maybe in a splash form:
> Call CloseButtonState(False) 'Disables X
> Call CloseButtonState(True) 'Enables X
> ***********************
>
> but I get a "Variable not Defined" error when it is called. Where are the
> variables MF_BYCOMMAND and MF_GRAYED declared?
>
> Thanks for any help...



They're probably declared in the Declarations section of the module you
copied that from, and you probably omitted to copy them. However ...

The more common way to handle this is to open a hidden form at startup, and
use the Unload event of that form either to do your housekeeping tasks or
else to cancel the unload, and hence the closing of Access, unless you can
determine that the user did click your Exit button.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Reply With Quote
 
KenR
Guest
Posts: n/a
 
      5th Sep 2008
I didn't copy the code from a module, it was posted, in its entirety, in this
forum.

However, I'm happy to use a different method... whatever will work

I already have a hidden form running at all times in the database, so I can
include any necessary code in the form's unload event. The housekeeping
tasks I need to perform may require some user involvement, so I can't just
attach the tasks to the event.

I would like to cancel the close event if the user didn't exit using the
button I provided. However, I don't know how to "cancel the unload," as you
referred to it. Can you help with that?

thanks

Ken

"Dirk Goldgar" wrote:

>
> They're probably declared in the Declarations section of the module you
> copied that from, and you probably omitted to copy them. However ...
>
> The more common way to handle this is to open a hidden form at startup, and
> use the Unload event of that form either to do your housekeeping tasks or
> else to cancel the unload, and hence the closing of Access, unless you can
> determine that the user did click your Exit button.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>

 
Reply With Quote
 
Armen Stein
Guest
Posts: n/a
 
      5th Sep 2008
On Fri, 5 Sep 2008 13:13:17 -0400, "Dirk Goldgar"
<(E-Mail Removed)> wrote:

>The more common way to handle this is to open a hidden form at startup, and
>use the Unload event of that form either to do your housekeeping tasks or
>else to cancel the unload, and hence the closing of Access, unless you can
>determine that the user did click your Exit button.


It isn't a good practice to use Globals except only momentarily, but
just in case you are:

Remember that if you cancel the Unload event during a quit, any Global
variables have already been cleared out.

Armen Stein
Microsoft Access MVP
www.JStreetTech.com

 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      5th Sep 2008
"KenR" <(E-Mail Removed)> wrote in message
news:71B2A5B3-D534-4F99-830F-(E-Mail Removed)...
>I didn't copy the code from a module, it was posted, in its entirety, in
>this
> forum.
>
> However, I'm happy to use a different method... whatever will work
>
> I already have a hidden form running at all times in the database, so I
> can
> include any necessary code in the form's unload event. The housekeeping
> tasks I need to perform may require some user involvement, so I can't just
> attach the tasks to the event.
>
> I would like to cancel the close event if the user didn't exit using the
> button I provided. However, I don't know how to "cancel the unload," as
> you
> referred to it. Can you help with that?


Here's a way to manage it: Put an unbound checkbox control named
"chkOkayToClose" on the hidden form, with the default value False. In your
Exit command button's Click event, after you've taken care of your
housekeeping but before issuing your Quit command, add the line

Forms!YourHiddenFormName!chkOkayToClose = True

(changing the form name appropriately). In the Unload event of your hidden
form, put an event procedure like this:

'----- start of code -----
Private Sub Form_Unload(Cancel As Integer)

If Me!chkOkayToClose = False Then

MsgBox _
"Please click the Exit button to close this application.", _
vbExclamation, _
"Exit Using Button"

Cancel = True

End If

End Sub
'----- end of code -----

That ought to do it. Bear in mind Armen Stein's warning about global
variables. By the time you get to the hidden form's Unload event, they will
probably already have been cleared.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Reply With Quote
 
KenR
Guest
Posts: n/a
 
      5th Sep 2008
That worked like a charm!

Thanks!

Ken
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable Close Button or in other application or capture its proces Brian Microsoft Access VBA Modules 0 24th Oct 2008 06:38 PM
How do I disable the Access Application Close button in 2007. djlansing Microsoft Access VBA Modules 1 22nd Jul 2008 09:36 PM
[Access 2007] Problem to disable the Close Button (X) on the Access Application Window David Berthemet Microsoft Access 0 28th Feb 2007 11:33 AM
How can I disable the Application close button? =?Utf-8?B?TmVhbA==?= Microsoft Access Getting Started 3 23rd Sep 2005 01:01 AM
Disable Close X Button On Excel Application Celtic_Avenger Microsoft Excel Programming 2 31st Oct 2004 04:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:58 PM.