Cancel = true

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi I have a form which has 2 text boxes, one for userName and one for password and 2 buttons, one Enter and one Cancel. The article below is saying I need to make Cancel properties of a command button to True then I can use ESC key to cancel. I want to understand that better. So here is my understanding:

I have to have Sub cancel_click() macro which will unload the form but instead of clicking on Cancel button, I can press ESC key to cancel, That is all! I mean if I change the Cancel property to TRUE and if I do not have Sub cancel_Click() macro, then it wont work. Am I right. Thank you very much

Code:
Private Sub cancel_Click()
Unload pwd
End Sub


Private Sub enter_Click()
If (username.Value <> "" And password.Value <> "") Then
    MsgBox "logon successful"
Else
    MsgBox "logon fail"
End If
End Sub

[h=2]Using the Escape key to cancel[/h]If you want to allow the user to cancel using the Esc it is simple(but not obvious) to do. You set the Cancel property of your ‘Cancel’ button to True. When Esc is pressed the click event of your Cancel button will be used.

https://excelmacromastery.com/vba-user-forms-1/#Using_the_Escape_key_to_cancel
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Yes I did actually and it is working but to be honest, it does not make sense. That is why I wanted to confirm. Thank you
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top