Form.Close

K

kirkm

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
 
K

kirkm

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
 
F

FSt1

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
 
D

Dave Peterson

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
 
F

FSt1

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
 
K

kirkm

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
 
K

kirkm

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top