Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Disable Close Button
Deon Riley 
    
13 years ago
Hi Gregory, I needed to control user work flow process and Log User activity in a database I designed some time ago. One of the problems was to prevent Users from exiting the database using the big X (red) button. I did a little searching and found code and a procedure, which has worked for me and I still have the functionality of using the Minimize/Maximize buttons next to the big red X button so here it is:

1)I created a Global Module and named it

EnableDisableXButton
  
Placed the following code in this global module

Option Compare Database
Option Explicit

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal wRevert As Long) As Long
Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long

2) This sets the function so it can be called from anywhere inside the database forms

Public Sub AccessCloseButtonEnabled(pfEnabled As Boolean)
    
  On Error Resume Next

  Const clngMF_ByCommand As Long = &H0&
  Const clngMF_Grayed As Long = &H1&
  Const clngSC_Close As Long = &HF060&

  Dim lngWindow As Long
  Dim lngMenu As Long
  Dim lngFlags As Long

  lngWindow = Application.hWndAccessApp
  lngMenu = GetSystemMenu(lngWindow, 0)
  If pfEnabled Then
    lngFlags = clngMF_ByCommand And Not clngMF_Grayed
  Else
    lngFlags = clngMF_ByCommand Or clngMF_Grayed
  End If
  Call EnableMenuItem(lngMenu, clngSC_Close, lngFlags)
  
End Sub

3) Ok - now all you have to do is place the following VBA code in your Databases start up Splash-screen or User Log on or Main Menu/Switchboard Form s On Open Event

Private Sub Form_Open(Cancel As Integer)

     Call AccessCloseButtonEnabled(False)
    
End Sub

4) You can also use a single line of code in other parts of the databases Form s On Close event as shown below to enable to big red X button.    

Private Sub Form_Close()

Call AccessCloseButtonEnabled(True)

End Sub

5) However, if you are controlling user flow then the above statement defeats the object of disabling the red X button in the first place.

Just make sure you have created appropriate Exit/Quit the database buttons or else your users will be stuck and have to use Ctl Alt Delete to log out etc.

I have just re-tested the function and it works and I hope this helps and best regards,

Deon

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/16/2026 1:54:22 PM. PLT: 1s