Query Unload Prompt with an option to disable.

Posted on 2006-05-17
Last Modified: 2011-08-18
I added a message box to ask user if they really want to quit the app or not - something like

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

Question by:larrysy
    LVL 11

    Expert Comment

    '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.
    LVL 12

    Expert Comment

    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.
    LVL 13

    Accepted Solution


    you have to create a custom yes/no form, or use subclassing
    LVL 11

    Expert Comment


    Author Comment

    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.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now