Query Unload Prompt with an option to disable.

I added a message box to ask user if they really want to quit the app or not - something like
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20876764.html

How do I add a check box so that the user can choose whether to show the message or not (disable the exit prompt)?

larrysyAsked:
Who is Participating?
 
Mark_FreeSoftwareCommented:

you have to create a custom yes/no form, or use subclassing
0
 
TreyHCommented:
'A crude example:

Option Explicit

Dim m_bOptionQuit       As Boolean

Private Sub Check1_Click()
    Select Case Check1.Value
        Case vbChecked
            m_bOptionQuit = True
        Case vbUnchecked
            m_bOptionQuit = False
    End Select
   
End Sub

Private Sub Form_Load()
    m_bOptionQuit = True
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If m_bOptionQuit Then
        If MsgBox("Do you really want to quit?", vbOKCancel) = vbCancel Then
            Cancel = 1
        End If
    End If
End Sub

'I used a simple check box to toggle the module level variable but usually other methods are used to store user settings
' and then retrieved upon program startup.
0
 
jkaiosIT DirectorCommented:
Store the value of your module-level variable "m_bOptionQuit" into a file (i.e., INI file) or in the Registry.

The next time your program loads, you just read the value from the INI file or the Registry and then assign
it to the "m_bOptionQuit" variable followed by setting the "Value" property of the CheckBox control.
0
 
TreyHCommented:
lol
0
 
larrysyAuthor Commented:
My question is if there is any easy way to add a check box in the pop-up box itself (not the main form) for the purpose.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.