Hi folks,
I'm wondering how to close a VB6 multiform application using the red x on the main form. There should be a message box that lets the user confirm the exit ( yes ), or ( no ) resume the application.
Thank You!
Hi folks,
I'm wondering how to close a VB6 multiform application using the red x on the main form. There should be a message box that lets the user confirm the exit ( yes ), or ( no ) resume the application.
Thank You!
's QueryUnload approach is the right starting point: the QueryUnload event runs before Unload and gives you a way to cancel closing (so the red X can be intercepted). 's suggestion to mark the thread solved is fine once the code works — but a few refinements help make the behavior robust in real-world multi-form apps.
Key points to harden the solution without repeating the code already posted:
Testing checklist:
Jump to Post— kinwang2009 7Good job TDuck, thats how you learn. Please mark it as Solved if your problem is solved.
thanks
Hi folks,
I'm wondering how to close a VB6 multiform application using the red x on the main form. There should be a message box that lets the user confirm the exit ( yes ), or ( no ) resume the application.
Thank You!
A nice way to close a form using the red x in a multi form application.
I found it myself. Hope this helps others.
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
' If message box conflicts with other forms.
frm_A_About.Visible = False
frm_B.Visible = False
' Only prompt if the user hits the red X
If UnloadMode = 0 Then
If MsgBox("Are you sure you want to quit?", vbYesNo Or vbQuestion) = vbNo Then Cancel = True
Unload frm_A
Unload frm_B
Unload frm_C
Unload frm_Z
Set frm_A = Nothing
Set frm_B = Nothing
Set frm_C = Nothing
Set frm_Z = Nothing
End If
End Sub
Good job TDuck, thats how you learn. Please mark it as Solved if your problem is solved.
thanks
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.