p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

access thread: Disable the Access Close button


Message #1 by kennyalligood@h... on Fri, 14 Jun 2002 17:07:33
Does anyone know of a way to disable the Close button and the Control Box 
of the Access application? I'm looking for a way to force the user to 
activate a shut down routine instead of closing Access by using either the 
Close button or Control Box. Any assistance would be greatly appreciated...

Thanx in advance

Kenny 
Message #2 by PStreeter@C... on Fri, 14 Jun 2002 10:48:15 CST
On Fri, 14 Jun 2002 17:07:33 kennyalligood@h... wrote:

> Does anyone know of a way to disable the Close button and the Control Box 
> of the Access application? I'm looking for a way to force the user to 
> activate a shut down routine instead of closing Access by using
> either the  Close button or Control Box. Any assistance would be greatly
> appreciated...

It's a parameter under properties -> format for the form. I generally 
do exactly that and add my own exit button. That is where you could 
do what you want to do.

Paul


Message #3 by kennyalligood@h... on Fri, 14 Jun 2002 18:25:22
Thanx for the reply but I believe we are talking about different forms. I 
was asking about the Access application window and not a form that I 
created. Which were you referring to? If it was the application how do I 
get to the properties setup?? Thanx again.

Message #4 by "Clive Astley" <clive.astley@k...> on Fri, 14 Jun 2002 18:50:54
I've never done this successfully so cannot advise. But in the archives of 
this and several of the Yahoo Access groups there are methods to do what 
you ask. They all seem rather complex.

Hope this helps a little. Best wishes,
Clive


> Does anyone know of a way to disable the Close button and the Control 
Box 
o> f the Access application? I'm looking for a way to force the user to 
a> ctivate a shut down routine instead of closing Access by using either 
the 
C> lose button or Control Box. Any assistance would be greatly 
appreciated...

> Thanx in advance

> Kenny 
Message #5 by "cdebiasio@t... on Fri, 14 Jun 2002 19:51:27 +0200 (CEST)
Hi!

The point is, if you deploy an application, with a proper user interface, you 
should PREVENT the user to use the ... common User's interface! I mean, you'd 
develop you own application menu, or draw a form acting as a menu... hiding 
the "real" Access interface. That's why Access developing is not always 
considered a "real" developement - it is always there, in some capacity, even 
if you use the Developers Kit.

It's pretty easy to hide the database form (from Tools/Startup options), but 
you have to build your own menu, your own toolbar, your own... interface. That 
way you'll be in control.

And that's why it's not easy to hide those buttons - if you are really in need 
of doing so, it means you have to move to another solution.

   Claudio de Biasio
     Team 97 S.r.l.

Quoting Clive Astley <clive.astley@k...>:

> I've never done this successfully so cannot advise. But in the archives
> of 
> this and several of the Yahoo Access groups there are methods to do what
> 
> you ask. They all seem rather complex.
> 
> Hope this helps a little. Best wishes,
> Clive
> 
> 
> > Does anyone know of a way to disable the Close button and the Control
> 
> Box 
> o> f the Access application? I'm looking for a way to force the user to
> 
> a> ctivate a shut down routine instead of closing Access by using either
> 
> the 
> C> lose button or Control Box. Any assistance would be greatly 
> appreciated...
> 
> > Thanx in advance
> 
> > Kenny 
> 
Message #6 by "Leo Scott" <leoscott@c...> on Fri, 14 Jun 2002 10:56:29 -0700
The easiest way to accomplish this is have a startup form that you never
close except through your controlled routine.  In that forms Unload event
set cancel to a global level boolean variable, gblnNoExit.  This should be
set to True in the startup form's Load event.  The only place it should be
set to false is in your controlled exit procedure.  You should also give the
user some kind of message in the startup form's Unload event as to why
Access is not closing and how to properly close your application.  This may
not prevent Access being closed by the Task Manager in some OS versions.

|-----Original Message-----
|From: kennyalligood@h... [mailto:kennyalligood@h...]
|Sent: Friday, June 14, 2002 5:08 PM
|To: Access
|Subject: [access] Disable the Access Close button
|
|
|Does anyone know of a way to disable the Close button and the Control Box
|of the Access application? I'm looking for a way to force the user to
|activate a shut down routine instead of closing Access by using either the
|Close button or Control Box. Any assistance would be greatly appreciated...
|
|Thanx in advance
|
|Kenny
|

Message #7 by Patrick_Slesicki@d... on Fri, 14 Jun 2002 14:52:55 -0700
Check out the following link courtesy of the Access Web:


http://www.mvps.org/access/general/gen0005.htm




                                                                                                                         
                    PStreeter@C...                                                                                 
                              .Mensa.Org       To:     "Access" <access@p...>                                    
                                               cc:                                                                       
                       06/14/02 09:48 AM       Subject:     [access] Re: Disable the Access Close button                 
                       Please respond to                                                                                 
                                "Access"                                                                                 
                                                                                                                         
                                                                                                                         




On Fri, 14 Jun 2002 17:07:33 kennyalligood@h... wrote:

> Does anyone know of a way to disable the Close button and the Control Box
> of the Access application? I'm looking for a way to force the user to
> activate a shut down routine instead of closing Access by using
> either the  Close button or Control Box. Any assistance would be greatly
> appreciated...

It's a parameter under properties -> format for the form. I generally
do exactly that and add my own exit button. That is where you could
do what you want to do.

Paul






Message #8 by "George Oro" <george@c...> on Sat, 15 Jun 2002 08:52:02 +0400
Paul,
Check my post Subject: Tips of the Day...

Cheers,
George


-----Original Message-----
From: Patrick_Slesicki@d... [mailto:Patrick_Slesicki@d...]
Sent: Saturday, June 15, 2002 1:53 AM
To: Access
Subject: [access] Re: Disable the Access Close button



Check out the following link courtesy of the Access Web:


http://www.mvps.org/access/general/gen0005.htm




                                                                                                                         
                    PStreeter@C...                                                                                 
                              .Mensa.Org       To:     "Access" <access@p...>                                    
                                               cc:                                                                       
                       06/14/02 09:48 AM       Subject:     [access] Re: Disable the Access Close button                 
                       Please respond to                                                                                 
                                "Access"                                                                                 
                                                                                                                         
                                                                                                                         




On Fri, 14 Jun 2002 17:07:33 kennyalligood@h... wrote:

> Does anyone know of a way to disable the Close button and the Control Box
> of the Access application? I'm looking for a way to force the user to
> activate a shut down routine instead of closing Access by using
> either the  Close button or Control Box. Any assistance would be greatly
> appreciated...

It's a parameter under properties -> format for the form. I generally
do exactly that and add my own exit button. That is where you could
do what you want to do.

Paul








Message #9 by "Clive Astley" <clive.astley@k...> on Sun, 16 Jun 2002 13:58:59
Check my post Subject: Tips of the Day...

Hi George,
Where do we find this post please?
Best wishes,
Clive





Message #10 by "Amy Wyatt" <amyw@c...> on Mon, 17 Jun 2002 18:57:46
In case you can't find it in the archives, here is the code:

Option Compare Database
Option Explicit

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

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

Get User Login Name from System
Declare Function WNetGetUser Lib "mpr.dll" _
   Alias "WNetGetUserA" (ByVal lpName As String, _
   ByVal lpUserName As String, lpnLength As Long) As Long
 
Global Const gcNO_ERROR = 0        'The Function call was successful
Global Const gcUserNotFound = 94

Public Function gUtil_GetUsersID() As String
    ' Buffer size for the return string.
    Const lpnLength As Integer = 255
    
    ' Get return buffer space.
    Dim status As Integer
    
    ' For getting user information.
    Dim lpName, lpUserName As String
    
    ' Assign the buffer size constant to lpUserName.
    lpUserName = Space$(lpnLength + 1)
    
    ' Get the log-on name of the person using product.
    status = WNetGetUser(lpName, lpUserName, lpnLength)
    
    ' See whether error occurred.
    If status = gcNO_ERROR Then
       ' This line removes the null character. Strings in C are null-
       ' terminated. Strings in Visual Basic are not null-terminated.
       ' The null character must be removed from the C strings to be used
       ' cleanly in Visual Basic.
       lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
    Else
       ' An error occurred.
       lpUserName = "UNKNOWN"
    End If
    
    gUtil_GetUsersID = lpUserName
End Function

You then have to call it on open of a form or autoexec it on open of the 
application. I have tried it but I am more comfortable with using a Global 
defined at open to one thing and then not allowing the close of my main 
form unless this Global variable is a certain value. Then the close/exit 
routine I write will change the value of the global so the form will close 
and the application can exit.

Hope this helps,

Amy


> Does anyone know of a way to disable the Close button and the Control 
Box 
o> f the Access application? I'm looking for a way to force the user to 
a> ctivate a shut down routine instead of closing Access by using either 
the 
C> lose button or Control Box. Any assistance would be greatly 
appreciated...

> Thanx in advance

> Kenny 
Message #11 by "Kenny Alligood" <kennyalligood@h...> on Mon, 17 Jun 2002 13:57:23 -0400
------=_NextPart_001_0001_01C21606.E79A0200
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Where would I find what you are talking about?

Kenny

----- Original Message -----
From: Clive Astley
Sent: Sunday, June 16, 2002 8:51 AM
To: Access
Subject: [access] Re: Disable the Access Close button


Check my post Subject: Tips of the Day...

Hi George,
Where do we find this post please?
Best wishes,
Clive





to unsubscribe send a blank email to G
et more from the Web.  FREE MSN Explorer download : http://explorer.msn.c
om

Message #12 by "George Oro" <george@c...> on Wed, 19 Jun 2002 16:50:03 +0400
Check my Post title "Tips of the Day", if you can't find it just let me know.

Cheers,
George


-----Original Message-----
From: PStreeter@C...
[mailto:PStreeter@C...]
Sent: Friday, June 14, 2002 8:48 PM
To: Access
Subject: [access] Re: Disable the Access Close button


On Fri, 14 Jun 2002 17:07:33 kennyalligood@h... wrote:

> Does anyone know of a way to disable the Close button and the Control Box 
> of the Access application? I'm looking for a way to force the user to 
> activate a shut down routine instead of closing Access by using
> either the  Close button or Control Box. Any assistance would be greatly
> appreciated...

It's a parameter under properties -> format for the form. I generally 
do exactly that and add my own exit button. That is where you could 
do what you want to do.

Paul




Message #13 by "Kenny Alligood" <kennyalligood@h...> on Wed, 19 Jun 2002 13:43:04 -0400
Thanx for your help I got it to work with a minor modification. I set my 
autoexec macro with the RunCode EnableDisableControlBox(False, 0).

Kenny


>From: "Amy Wyatt" <amyw@c...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Re: Disable the Access Close button
>Date: Mon, 17 Jun 2002 18:57:46
>
>In case you can't find it in the archives, here is the code:
>
>Option Compare Database
>Option Explicit
>
>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
>
>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
>
>Get User Login Name from System
>Declare Function WNetGetUser Lib "mpr.dll" _
>    Alias "WNetGetUserA" (ByVal lpName As String, _
>    ByVal lpUserName As String, lpnLength As Long) As Long
>
>Global Const gcNO_ERROR = 0        'The Function call was successful
>Global Const gcUserNotFound = 94
>
>Public Function gUtil_GetUsersID() As String
>     ' Buffer size for the return string.
>     Const lpnLength As Integer = 255
>
>     ' Get return buffer space.
>     Dim status As Integer
>
>     ' For getting user information.
>     Dim lpName, lpUserName As String
>
>     ' Assign the buffer size constant to lpUserName.
>     lpUserName = Space$(lpnLength + 1)
>
>     ' Get the log-on name of the person using product.
>     status = WNetGetUser(lpName, lpUserName, lpnLength)
>
>     ' See whether error occurred.
>     If status = gcNO_ERROR Then
>        ' This line removes the null character. Strings in C are null-
>        ' terminated. Strings in Visual Basic are not null-terminated.
>        ' The null character must be removed from the C strings to be used
>        ' cleanly in Visual Basic.
>        lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
>     Else
>        ' An error occurred.
>        lpUserName = "UNKNOWN"
>     End If
>
>     gUtil_GetUsersID = lpUserName
>End Function
>
>You then have to call it on open of a form or autoexec it on open of the
>application. I have tried it but I am more comfortable with using a Global
>defined at open to one thing and then not allowing the close of my main
>form unless this Global variable is a certain value. Then the close/exit
>routine I write will change the value of the global so the form will close
>and the application can exit.
>
>Hope this helps,
>
>Amy
>
>
> > Does anyone know of a way to disable the Close button and the Control
>Box
>o> f the Access application? I'm looking for a way to force the user to
>a> ctivate a shut down routine instead of closing Access by using either
>the
>C> lose button or Control Box. Any assistance would be greatly
>appreciated...
>
> > Thanx in advance
>
> > Kenny


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


  Return to Index