How to prevent a form/app from unloading , even if you use the taskmanager? Then try this code… (It works for me 😉
Original Author: Riaan Aspeling
Side Effects
Make sure you DO have a way of closing your form/app
Code
Private Sub Form_QueryUnload(cancel As Integer, UnloadMode As Integer)
'To cancel the unload make the cancel = true. Don't do it
'on the vbAppTaskManager one though.
Dim ans As String
Select Case UnloadMode
Case vbFormControlMenu 'Value 0
'This will be called if you select the close from the little icon
'menu on top and left of the form.
cancel = False
Case vbFormCode 'Value 1
'This will be called if your code requested a unload
cancel = False
Case vbAppWindows 'Value 2
'vbAppWindows is triggered when you shutdown Windows and your app is still
'running. Added by Jim MacDiarmid
cancel = False
End
Case vbAppTaskManager 'Value 3
'You have to allow the taskmanager to close the program, else you get
'that nasty 'App not responding, close anyway' dialog :<
'The clever way arround it would be to restart your program
'This would be used for a password screen!
cancel = False
x = Shell(App.Path & "" & App.EXEName, vbNormalFocus)
End
Case vbFormMDIForm 'Value 4
'This code is called from the parent form
cancel = False
End Select
End Sub