CancelClose ignoring return false

Hello. I have a project still in RB 2012v2.1. I have run across that I have never seen before before.

In the app.CancelClose, I want to simply do a check of some data and then post a reminder to the user before allowing the app to close. If I add something as simple as a Msgbox to the code first, it seems to completely ignore even an explicit return false and seems to act like I returned true:

[code] MsgBox “not synced”

return false[/code]

If I comment out the MsgBox line it does respond to the explicit false correctly:

[code] 'MsgBox “not synced”

return false[/code]

I have simplified the code above to reduce it to the essence of the issue…down to just one little message box. Any ideas why this is failing?


Tried this, could not reproduce the problem. Have you tried with just the code you posted ?

You should be returning True if you want to cancel the close. Returning False is the same as not implementing the event.

Might it be because calling MSGBOX, in turn causes the window in question to refire its ACTIVATE event?

You are right it does fire activate. But the code the OP posted does not refer to anything there. I suspect his actual code is more complex.

Thanks for your replies, guys.

The code that I want to implement is more complex. My example code as I posted it with the Msgbox causes the CancelClose to be canceled until it is commented out. Remember this is the APP event, not a window. I chose to reduce it down to just a MsgBox thinking that it could not affect other windows.

I will add that this occurs when issuing a Quit from a menu. If the last Window is closed, say with the CloseButton, it runs through the app.CancelClose event first as it should. But instead of failing, it displays the MsgBox and continues to close correctly. IT DOES NOT CANCEL the CLOSE as the other method does using the Quit method.

I will keep on trying to track it down.


I am sorry, but I tried your example code in app.CancelClose with RB2012R1.2 on Mac and it quits fine after the MsgBox is OK-ed. That is why I suspect something else is afoot in the rest of your code.

Unless this is on PC and another behavior is there ?

Maybe you could set App.Autoquit to True and simply close all windows after the msgbox ?

Don’t understand why it does not work for you or why you would need to do this, but try:

Create your own dialog . It it’s close event Just put

In App Class add a property
ReallyClosing as Boolean

If ReallyClosing Then Return False

ReallyClosing = True
Dim D as New MyDialog
Return False

Sorry for the delay. I am just getting back to this issue.

After spending a another perplexing good bit of time, I finally had to admit defeat. It was not worth spending more time on. I moved this routine to a Window CancelClose, instead of the app, where it works without issue.

Thanks everyone for all of your suggestions.


I think you skipped this part:

Thanks, Tim, but that is what I wanted to do. I wanted to continue with the Close and it was canceling it when I added any UI activity, even a msgbox, regardless of returning an explicit false.

I handled it another way, so the issue is resolved via a workaround.