Accelerator Property
Applies To
CheckBox control, CommandButton control, Label control, OptionButton control, Page object, Tab object, ToggleButton control.
Description
Sets or retrieves the accelerator key for a control.
Syntax
object.Accelerator [= String]
The Accelerator property syntax has these parts:
Part | Description |
|
object | Required. A valid object. |
String | Optional. The character to use as the accelerator key. |
Remarks
To designate an accelerator key, enter a single character for the Accelerator property. You can set Accelerator in the control's property sheet or in code. If the value of this property contains more than one character, the first character in the string becomes the value of Accelerator.
When an accelerator key is used, there is no visual feedback (other than focus) to indicate that the control initiated the Click event. For example, if the accelerator key applies to a CommandButton, the user will not see the button pressed in the interface. The button receives the focus, however, when the user presses the accelerator key.
If the accelerator applies to a Label, the control following the Label in the tab order, rather than the Label itself, receives the focus.
Example
This example changes the Accelerator and Caption properties of a CommandButton each time the user clicks the button by using the mouse or the accelerator key. The Click event contains the code to change the Accelerator and Caption properties.
To try this example, paste the code into the Declarations section of a form containing a CommandButton named CommandButton1.
Private Sub UserForm_Initialize()
CommandButton1.Accelerator= "C" 'Set accelerator key to ALT + C
End Sub
Private Sub CommandButton1_Click ()
If CommandButton1.Caption = "OK" Then 'Check caption, then change it.
CommandButton1.Caption = "Clicked"
CommandButton1.Accelerator = "C" 'Set accelerator key to ALT + C
Else
CommandButton1.Caption = "OK"
CommandButton1.Accelerator = "O" 'Set accelerator key to ALT + O
End If
End Sub