Valhalla Legends Forums Archive | Visual Basic Programming | Form_Unload Cancel Prop

AuthorMessageTime
CrAz3D
vb6
I am trying to get the form to not close when I click the 'close' button. I have accomplished this by using [code]Cancel=1[/code]

The only problem I am having is that the form I don't want to close is a MDIChild, & it will not close when I try to close the main MDI form. Any ideas?

August 31, 2003, 6:21 PM
Skywing
Maybe you could set a flag in Form_Unload or whatever for your main window, and check that flag in Form_Unload for your MDIClient to determine whether or not it should allow itself to be closed?
August 31, 2003, 6:33 PM
CrAz3D
okey dokey, thank ya, I'lls ee what that does.
---
Well, I tried this:
[code]If UnloadCancel = False Then
Cancel = 1
End If[/code] It didn't seem to work. Any other ideas?
August 31, 2003, 6:41 PM
Grok
Use Query_Unload instead. It provides the mechanism you need to decide the reason why the form is closing. If the reason is the system menu (user clicked) then set Cancel = True. For all other reasons, set Cancel = False.

[code]Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Select Case UnloadMode
Case vbFormControlMenu '0 The user chose the Close command from the Control menu on the form.
Cancel = True
Case vbFormCode '1 The Unload statement is invoked from code.
Case vbAppWindows '2 The current Microsoft Windows operating environment session is ending.
Case vbAppTaskManager '3 The Microsoft Windows Task Manager is closing the application.
Case vbFormMDIForm '4 An MDI child form is closing because the MDI form is closing.
Case vbFormOwner '5 A form is closing because its owner is closing
End Select
End Sub[/code]
August 31, 2003, 7:19 PM
CrAz3D
Thank ya kindly

EXTREMELY KINDLY! ;D
August 31, 2003, 7:35 PM

Search