Cancel Property

Cancel Property

See Also                  Applies To        

Returns or sets a value indicating whether a CommandButton 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.