I'm not familiar with Query_Unload but here is how to trap a number of close events:
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Select Case UnloadMode
Case vbFormControlMenu
MsgBox "The user chose the Close command (the ""X"") from the Control menu on the form."
Case vbFormCode
MsgBox "The Unload statement is invoked from code."
Case vbAppWindows
MsgBox "The current Microsoft Windows operating environment session is ending."
Case vbAppTaskManager
MsgBox "The Microsoft Windows Task Manager is closing the application."
Case vbFormMDIForm
MsgBox "An MDI child form is closing because the MDI form is closing."
Case vbFormOwner
MsgBox "A form is closing because its owner is closing."
End Select
End Sub
Private Sub Form_Load()
Temp = DisableCloseButton(Form1) = False ' where Form1 is the name of your form
End Sub
and paste this in a module
Code:
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&
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
Last edited by Siddharth Rout; Oct 2nd, 2008 at 09:48 AM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero