Credit for the Hide/Unhide code goes to crptcblade.
VB Code:
Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd _ As Long, ByVal bRevert As Long) As Long Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu _ As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long Public Declare Function DrawMenuBar Lib "user32" (ByVal hwnd _ As Long) As Long Private Const MF_BYCOMMAND = &H0& Private Const SC_CLOSE = &HF060& Public Sub SetXState(frm As Form, blnState As Boolean) Dim hMenu As Long hMenu = GetSystemMenu(frm.hwnd, blnState) Call RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND) Call DrawMenuBar(frm.hwnd) End Sub
Example of Usage:
VB Code:
Private Sub Command1_Click() If opt(0).Value = True Then SetXState Me, True 'enable the X button ElseIf opt(1).Value = True Then SetXState Me, False 'disable the X button End If End Sub
You can however avoid all that and just do this
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If UnloadMode = vbFormControlMenu Then cmdExit = True ' Change cmdExit to the name of your exit command button ' and the code behind that button will be executed End If End Sub




Reply With Quote