MrExcel Publishing
Your One Stop for Excel Tips & Solutions

VBA Property: "Cancel" for a command button


Posted by Kevin James on June 05, 2001 1:52 PM

I don't (and can't) have helpfiles loaded on my work PC. The Cancel property has only two arguments, True or False. What purpose does this property serve? I've tried it on a button I labeled Cancel (with the corresponding subroutine to unload the form), and whether the property is set True or False, the form unloads.


Posted by Damon Ostrander on June 05, 2001 2:25 PM

Kevin,

Here is a copy of the Microsoft Cancel Property help file:

Cancel Property

Copyright(c) 1996 Microsoft Corporation.

Returns or sets a value indicating whether a command button is the Cancel button on a form.

Syntax

object.Cancel [= Boolean]

The Cancel property syntax has these parts:

Part Description
object Required. A valid object.
Boolean Optional. Whether the object is the Cancel button.
Settings

The settings for Boolean are:

Value Description
True The CommandButton is the Cancel button.
False The CommandButton is not the Cancel button (default).
Remarks

A CommandButton or an object that acts like a command button can be designated as the default command button. For OLE container controls, the Cancel property is provided only for those objects that specifically behave as command buttons.
Only one CommandButton on a form can be the Cancel button. Setting Cancel to True for one command button automatically sets it to False for all other objects on the form. When a CommandButton's Cancel property is set to True and the form is the active form, the user can choose the command button by clicking it, pressing ESC, or pressing ENTER when the button has the focus.

A typical use of Cancel is to give the user the option of canceling uncommitted changes and returning the form to its previous state.
You should consider making the Cancel button the default button for forms that support operations that can’t be undone (such as delete). To do this, set both Cancel and the Default property to True.

Copyright(c) 1996 Microsoft Corporation.

Posted by Kevin James on June 05, 2001 3:24 PM

thank you.

Damon,

Hello. A new "face" on the board. Don't believe we've met. Thanks. I should have figured it would be something simple.

Kevin