PDA

View Full Version : Activating ESCAPE KEY



yogeshwarv
10-13-2006, 03:09 AM
Sir,

I have made a user form. It activates when I click to activate the same and unloadeds when i press cancelled button.

I want to know a procedure if I press ESC key on keyboard the activated form should unload immediately.

I believe this can be done by on key procedure but i have no idea how to apply this procedure.

Please help....

mvidas
10-13-2006, 05:29 AM
yogeshwarv,

Add a command button to the userform. Set the "Cancel" property of that button to true, and in the commandbutton_click event code put "Unload Me", likePrivate Sub CommandButton1_Click()
Unload Me
End SubMatt

d4vem
10-13-2006, 09:54 AM
If my understanding is correct you want to close the Userform when the ESCAPE key is pressed.

If so insert the following code onto the private sub userform.

Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Unloads a Userform when Escape Button pressed
'To use other keys to unload the userform
'activate the msgbox after the if statement to
'get the "KeyAscii" value (ESC button = 27)
'and change the if statement to the required value

'MsgBox KeyAscii

'Get the key Ascii value

KeyP = KeyAscii
'Perform the proceedure
If KeyP = "27" Then Unload UserForm1

'or if you prefer to hide the userform activate
'the following line of code and blank the previous
'line

'If KeyP = "27" Then UserForm1.Hide


End Sub

d4vem
10-13-2006, 10:04 AM
Missed something. In the "unload" statement change to "Unload Me" as oppossed to "Unload Userform1"

yogeshwarv
10-16-2006, 04:44 AM
Thanks D4Vam,
THIS IS WHAT I WANTED TO LEARN.

THANKS ONCE AGAIN!!!!! GREAT HELP!!!!!!!!!

YOGESHWAR