Disable Close Button in Userform (Visual Basic)
Option Explicit
'API Declarations
Const MF_BYPOSITION = &H400&
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
Public Sub DisableCloseWindowButton(frm As Form)
Dim hSysMenu As Long
'Get the handle of the Window
hSysMenu = GetSystemMenu(frm.hwnd, 0)
'Disable the close button of the Form
RemoveMenu hSysMenu, 6, MF_BYPOSITION
'Remove the seperator bar
RemoveMenu hSysMenu, 5, MF_BYPOSITION
End Sub
Tuesday, August 21, 2007
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.
It Works fine.. thank you :)
ReplyDeleteI get a Compile error: User-defined type not defined.
ReplyDeleteThe error appears to be in the line:
Public Sub DisableCloseWindowButton(frm As Form)
Apparently there is no such thing as a Form type...
I receive the same message:
ReplyDeleteUser-defined type not defined.
Public Sub DisableCloseWindowButton(frm As Form)