#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default 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




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default 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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default 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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default 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
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Close a form when you click outside of the form Alex St-Pierre Excel Programming 1 June 19th 08 10:57 PM
Call user form from ThisWorkbook; close file if form closed XP Excel Programming 2 July 20th 07 07:04 PM
How do I close form PeterW Excel Programming 3 March 31st 07 12:50 PM
Close form... pianoman[_34_] Excel Programming 6 June 5th 06 02:09 PM
Close Form with VBA William C. Smith Excel Programming 3 September 2nd 03 05:28 AM


All times are GMT +1. The time now is 06:01 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"