Solved

Unload Me

Posted on 2004-08-10
7
1,250 Views
Last Modified: 2012-06-27
Hi everyone, I'm trying to abort exiting the program if user choses no to exit on a msgbox. that sets the var AbortTask = true. this that I wrote doesn't work. I don't understang why...

Can somebody help me?

Private Sub Form_Unload(Cancel As Integer)
    If LoadingBar.Visible = True Then
        Cancel = 1
        Exit Sub
    Else: End If
   
    If AbortTask = True Then
        AbortTask = False
        Cancel = 1
        Exit Sub
    Else: End If
End Sub

The msgbox must be from another form or sub, so I have to work with a boolean var I guess.
0
Comment
Question by:igfp
7 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 11761626

Rather use the QueryUnload even for checking if the user really wants to close:

Private Sub Form_QueryUnload(unloadmode, cancel ... i don't know the arguments by heart)
    If LoadingBar.Visible = True Then
        Cancel = 1
        Exit Sub
    End If
   
    If AbortTask = True Then
        AbortTask = False
        Cancel = 1
        Exit Sub
    End If
End Sub


Alternative:

Private Sub Form_QueryUnload(unloadmode, cancel ... i don't know the arguments by heart)
    If LoadingBar.Visible = True Then
        Cancel = 1
        Exit Sub
    End If

    if unloadmode = vbFormControl then
       if msgbox ( 'do you really wanna quit?', vbyesno ) = vbno then
         cancel = true
       endif
    endif    

End Sub


CHeers
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 11761644
Where do you define AbortTask variable?

You should define in module as Public not on the form
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 11761653
Is the variable global?
When do you set it?
If the Unload procedure is in several Forms, the variable will be reset the first time that it is encountered.
I suggest stepping throught the code (set a breakpoint on the first line of the sub)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:igfp
ID: 11761669
Yes the var is set on a module as this: Public AbortTask as boolean
When the program is load it is set as false.

I tried query unload too, and it didn't work. don't know how...
0
 

Author Comment

by:igfp
ID: 11761678
I also made the breakpoint and the form actually passes the line: Cancel=1 it stops there. but afterwards, the program exits!
0
 
LVL 15

Assisted Solution

by:SRigney
SRigney earned 200 total points
ID: 11761709
Cancel = 1 should prevent the form from unloading, but if you have an End statement the Unload event won't stop that.
0
 
LVL 19

Accepted Solution

by:
Shauli earned 200 total points
ID: 11761952
'The message box should be placed in the quesryUnload event, and anywhere you want
'to exit just put "Unload FormName" or "Unload Me". Never use End anywhere in your form except as the last line in an Unload event,
'and try this code:

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MsgBox("Do you wish to exit", vbQuestion + vbYesNo, "My Application Control") = vbNo Then
    Cancel = True
    Exit Sub
End If
End Sub

S
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

740 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