ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Form.Close (https://www.excelbanter.com/excel-programming/423790-form-close.html)

kirkm[_8_]

Form.Close
 
Hi,

I'm having trouble detecting how a Form Closes.

I want to allow whatever is done to be cancelled (if the Forms Close
button is used) but as the .Hide and form unload routines always run
I can't tell if it closed via my code, or by the close button.

This HAS to be simple but I can't figure it !

Any suggestions?

Thanks - Kirk





kirkm[_8_]

Form.Close
 
On Tue, 10 Feb 2009 15:51:58 +1300, kirkm wrote:

Hi,

I'm having trouble detecting how a Form Closes.

I want to allow whatever is done to be cancelled (if the Forms Close
button is used) but as the .Hide and form unload routines always run
I can't tell if it closed via my code, or by the close button.

This HAS to be simple but I can't figure it !

Any suggestions?

Thanks - Kirk


SORRY ! Ignore the above... figured it out.

A boolean varible set False in Form initialise.
Then set True if any Form events occur.

But if there's any way to detect Close Button fired
That's the X on Form Top right, it's be useful



FSt1

Form.Close
 
hi
the code you wrote is closing the form. the question becomes .....which code
did you write that is closing the form. forms don't close themselves for no
perticular reason.
since you didn't post your code for us to analize...
have you tried step mode to see which code you wrote is closing the form????
i doubt the close button came with built in code.
Regards
FSt1

"kirkm" wrote:

Hi,

I'm having trouble detecting how a Form Closes.

I want to allow whatever is done to be cancelled (if the Forms Close
button is used) but as the .Hide and form unload routines always run
I can't tell if it closed via my code, or by the close button.

This HAS to be simple but I can't figure it !

Any suggestions?

Thanks - Kirk






Dave Peterson

Form.Close
 
Do you mean the X in the top rightcorner?

If yes, then maybe you could just call the cancel button's code:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Call CommandButton2_Click
End If
End Sub

Or just stop it completely????

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
msgbox "Don't use that X"
cancel = true
End If
End Sub

kirkm wrote:

Hi,

I'm having trouble detecting how a Form Closes.

I want to allow whatever is done to be cancelled (if the Forms Close
button is used) but as the .Hide and form unload routines always run
I can't tell if it closed via my code, or by the close button.

This HAS to be simple but I can't figure it !

Any suggestions?

Thanks - Kirk


--

Dave Peterson

FSt1

Form.Close
 
hi
sorry. i assumed that the close button was a button on your form. be more
persise in your posts so that nothing can be assumed.

sorry i could not help. see dave's post. i think even he may have been a tad
confused.

Regards
FSt1

"kirkm" wrote:

On Tue, 10 Feb 2009 15:51:58 +1300, kirkm wrote:

Hi,

I'm having trouble detecting how a Form Closes.

I want to allow whatever is done to be cancelled (if the Forms Close
button is used) but as the .Hide and form unload routines always run
I can't tell if it closed via my code, or by the close button.

This HAS to be simple but I can't figure it !

Any suggestions?

Thanks - Kirk


SORRY ! Ignore the above... figured it out.

A boolean varible set False in Form initialise.
Then set True if any Form events occur.

But if there's any way to detect Close Button fired
That's the X on Form Top right, it's be useful




kirkm[_8_]

Form.Close
 
On Mon, 09 Feb 2009 21:14:03 -0600, Dave Peterson
wrote:

Do you mean the X in the top rightcorner?


Yes... don't know what it's real name is so I called
it the 'close button'. (Hoping that would distinguish it from
a VB command.)

If yes, then maybe you could just call the cancel button's code:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Call CommandButton2_Click
End If
End Sub


Aha! That's exactly what I spent hours trying to code around. Works
perfectly. Thanks a million! Must remember that!

Cheers - Kirk

kirkm[_8_]

Form.Close
 
On Mon, 9 Feb 2009 20:53:02 -0800, FSt1
wrote:

hi
sorry. i assumed that the close button was a button on your form. be more
persise in your posts so that nothing can be assumed.


No worries... can be hard to describe something when you can hardly
figure it out yourself! I'll try though... this one now nicely
sorted. Thanks for helping.

Cheers - Kirk


All times are GMT +1. The time now is 07:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com