Preventing Form Close

danielhitch

New Member
Joined
Sep 8, 2008
Messages
48
Hi.

I have tried several ways to prevent a form of mine from closing.

My problem lies in the fact that I have got a particularly fragile ActiveX control that crashes if the form is closed using either the Application Close, Menu Close, or Tab close - It does not happen if I create a macro linked to a button that closes the form.

First of all, I tried creating an AutoExec but, this still crashes the control. So I have put together a bit of code that almost works, but doesn't. I need you guys to tell me how to make it work.

Here is my code:
Code:
Private Sub Form_Close()
If Close_Basic_Accident_Plot_Click Then
Cancel = False
Else
MsgBox "Please Use The Exit Button At The Bottom Left Of The Screen", vbOKOnly + vbExclamation, "Error"
Cancel = True
End If
End Sub

I have also tried the code on the form unload too with no success.

As far as I can see, the code kicks in after the close / unload command happens, therefore my click arguement in the If statement doesnt work.

What I need to happen is that the cancel command kicks in on every type of close appart from when the Close_Basic_Accident_Plot button is clicked.

Any ideas?

Thanks.

Dan.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You may create Custom Menus and Toolbars for your Application and disable default menus/toolbars through Tools-->Startup options. The Form control buttons (minimize, maximize,close buttons) can be removed through the Form's property settings. This will force the user to click on the Command Button to close the Form.

If you need help with designing menus and toolbars, visit the following links:

Custom Menus and Toolbars
Custom Menus and Toolbars-2
 
Upvote 0
have you tried creating a macro on the Onclose event that actually hides the form when closed instead of actually closing it?

It sounds kind of wierd, but on the On close event in the macro you choose open form, form name, and then last choice is Hidden instead of Normal.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top