?
Solved

Unload Me

Posted on 2004-08-10
7
Medium Priority
?
1,254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: 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 800 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 800 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

Technology Partners: 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!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Suggested Courses

770 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