-
:)
I got this code from a reply. I couldn't find my thread so I couldn't follow it up there. It's suppose to disable the X at the upper right corner of the Window which exits the form.
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Const MF_BYPOSITION = &H400&
Private Sub Form_Load()
RemoveMenu GetSystemMenu(Me.hWnd, 0), 6, MF_BYPOSITION 'removes the "X" box and the System Menu
End Sub
Well, if you'll try this code, it would look as if it would work the way it does. The X would become gray in color, but when I accidentally clicked the button, my form still exits!!!
Please help!!!
-
It's disabled for me.
But to keep your form from closing when the X button is clicked, add this to the Form_Unload() or Form_QueryUnload() event(s).
-
1 Attachment(s)
The API call worked just fine for me.
Here is my working example - just download the project I attacheed for you. I clicked on the 'X' and it doesn't cancel. If it doesn't work then and the queryunload event event with cancel = true like Matthew said.
btw - what version VB and Windows are you running?
:D
-
Matthew Gates: That code will prevent the Form from closing, but it will prevent it in all cases. What you need to do in this case is to make use of the UnloadMode argument of the QueryUnload() event.
Code:
If UnloadMode = 0 Then Cancel = True