Computer Learning Zone CLZ Access Excel Word Windows

Writing is perhaps the greatest of human inventions, binding together people who never knew each other, citizens of distant epochs. Books break the shackles of time. A book is proof that humans are capable of magic.

-Carl Sagan
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Home > Code Vault > Access VBA > Toggle Close Button
Toggle Close Button Code
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   10 days ago

Free Code

This is a sample of all of the glorious code that's available in my Code Vault which is available to Gold Members. If you'd like more information on joining, click here.

Description

This code will allow you to toggle ON or OFF the control box, maximize, minimize, and close buttons on a form.

Code

Place this code in a global module:

Option Compare Database
Option Explicit

Private Declare PtrSafe Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongA" _
    (ByVal hWnd As LongPtr, ByVal nIndex As Long) As LongPtr

Private Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongA" _
    (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr

Const GWL_STYLE As Long = -16
Const WS_SYSMENU As Long = &H80000

Public Sub ToggleCloseButton(frm As Form, Enable As Boolean)
    Dim lngStyle As LongPtr
    lngStyle = GetWindowLongPtr(frm.hWnd, GWL_STYLE)
    If Enable Then
        SetWindowLongPtr frm.hWnd, GWL_STYLE, (lngStyle Or WS_SYSMENU)
    Else
        SetWindowLongPtr frm.hWnd, GWL_STYLE, (lngStyle And Not WS_SYSMENU)
    End If
End Sub

Usage

Put this code wherever you'd like in a Form module. This will turn the current form's close button OFF:

ToggleCloseButton Me, False

Video

This is covered in the extended cut for my TechHelp video Toggle Close Button.

Questions

Post 'em if ya got 'em

 

 

Start a NEW Conversation
 
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
 
Subscribe
Subscribe to Toggle Close Button Code
Get notifications when this page is updated
 
 
 
 

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 2025 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 3/23/2025 4:49:27 PM. PLT: 0s
Keywords: code vault access toggle close button toggleclosebutton disable close button  PermaLink  Toggle Close Button Code