Consulting

Results 1 to 5 of 5

Thread: Activating ESCAPE KEY

  1. #1

    Activating ESCAPE KEY

    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....

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    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", like[vba]Private Sub CommandButton1_Click()
    Unload Me
    End Sub[/vba]Matt

  3. #3
    VBAX Regular
    Joined
    May 2006
    Posts
    67
    Location

    Try This

    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

  4. #4
    VBAX Regular
    Joined
    May 2006
    Posts
    67
    Location
    Missed something. In the "unload" statement change to "Unload Me" as oppossed to "Unload Userform1"

  5. #5
    Thanks D4Vam,
    THIS IS WHAT I WANTED TO LEARN.

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

    YOGESHWAR

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •