title | keywords | f1_keywords | ms.assetid | ms.date | ms.localizationpriority | |
---|---|---|---|---|---|---|
Click event, CommandButton control, Accelerator, Caption properties example |
fm20.chm5225180 |
|
f2d2210a-e69e-6dbb-6b3d-95ceb377bc84 |
11/14/2018 |
medium |
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 COMMAND + 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 COMMAND + C
Else
CommandButton1.Caption = "OK"
CommandButton1.Accelerator = "O"
'Set Accelerator key to COMMAND + O
End If
End Sub
[!includeSupport and feedback]