Visual Basic Reference
Returns or sets a value indicating whether a command button is the Cancel button on a form. This command button can be the CommandButton control or any object within an OLE container control that behaves as a command button.
object.Cancel [= boolean]
The Cancel property syntax has these parts:
|object||An object expression that evaluates to an object in the Applies To list.|
|boolean||A Boolean expression specifying whether the object is the Cancel button, as described in Settings.|
The settings for boolean are:
|True||The CommandButton control is the Cancel button.|
|False||(Default) The CommandButton control isn't the Cancel button.|
Use the Cancel property to give the user the option of canceling uncommitted changes and returning the form to its previous state.
Only one CommandButton control on a form can be the Cancel button. When the Cancel property is set to True for one CommandButton, it's automatically set to False for all other CommandButton controls on the form. When a CommandButton control's Cancel property setting is True and the form is the active form, the user can choose the CommandButton by clicking it, pressing the ESC key, or pressing ENTER when the button has the focus.
For OLE container controls, the Cancel property is provided only for those objects that specifically behave as command buttons.
Tip For a form that supports irreversible operations, such as deletions, it's a good idea to make the Cancel button the default button. To do this, set both the Cancel property and the Default property to True.