7 Years
Discussion Span
Last Post by Jx_Man

see if this help :


Option Explicit

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

Private Declare Function RemoveMenu Lib "user32" _
    (ByVal hMenu As Long, _
     ByVal nPosition As Long, _
     ByVal wFlags As Long) As Long
Private Const MF_BYPOSITION = &H400&

Function to disable

Public Function DisableCloseButton(frm As Form) As Boolean
    Dim lHndSysMenu As Long
    Dim lAns1 As Long, lAns2 As Long
    lHndSysMenu = GetSystemMenu(frm.hwnd, 0)
    lAns1 = RemoveMenu(lHndSysMenu, 6, MF_BYPOSITION)
    lAns2 = RemoveMenu(lHndSysMenu, 5, MF_BYPOSITION)
    DisableCloseButton = (lAns1 <> 0 And lAns2 <> 0)
End Function

Call When form load

Private Sub Form_Load()
Call DisableCloseButton(Me)
End Sub

If your question already answered then please mark thread as solved.
Mark thread as solved really helping another member when they read your thread too (no doubt for them to learn from your thread).

Votes + Comments
owesome :)
really great answer, as always.

thank you for your help and it was very useful to me. thank you JXman


You're Welcome...
Please Mark this thread as solved.
We've helps you several times but you never mark your thread as solved.
Mark thread as solved helping another member to learn from your threads.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.