Results 1 to 6 of 6

Thread: how can i enable ESC function (to close form)

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Philippines
    Posts
    49

    Question

    how can i enable the escape key function to close a form?


  2. #2
    Lively Member
    Join Date
    May 2000
    Location
    Norway
    Posts
    112
    If you have a Cancel button that closes the form, just set that buttons Cancel property to true. The Escape will then trigger the Cancel-buttons clickevent.

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298
    if not u can use this code in ur form,

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        '27 is the keycode for the escape key
        If KeyCode = 27 Then End
    End Sub

  4. #4
    Lively Member
    Join Date
    May 2000
    Location
    Norway
    Posts
    112
    But will that trigger if you are in a control on the form?

  5. #5
    Guest
    Originally posted by Thomas Halsvik
    But will that trigger if you are in a control on the form?
    Set the form's KeyPreview property to True and it will work, even if you have a control selected, it will still work.

  6. #6
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I can't say it too often, don't use end to stop your program, it's a rude way to quit your program.
    Use Unload Me to quit your program.

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    'VBKeyEscape is easier to follow then 27
    If KeyCode = vbKeyEscape Then
         Unload Me
    End If
    End Sub
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

Posting Permissions

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



Click Here to Expand Forum to Full Width