?
Solved

Unload form just by pressing 'Escape' key

Posted on 2000-03-20
5
Medium Priority
?
234 Views
Last Modified: 2012-05-05
Is there anyone who knows how to unload a form by merely pressing escape key?

I have tried keypress event of a form but the event is not triggered at all. And i would also like to know the ascii code of the escape key. Thank you.
0
Comment
Question by:klackons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 2635745
form1.keypreview = true


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = 27 And Shift = 0 Then Unload Me

End Sub
0
 
LVL 18

Accepted Solution

by:
deighton earned 100 total points
ID: 2635749
form1.keypreview = true


                   Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

                   If KeyCode = 27 And Shift = 0 Then Unload Me

                   End Sub


the escape key is ascii code 27
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 2635753
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If (KeyCode = 27) Then Unload Me
End Sub

don't forget to set keypreview property (on your form) to true
0
 
LVL 18

Expert Comment

by:deighton
ID: 2635774
vbKeyEscape

is the built in VB key word for the escape key

therefore

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

     If KeyCode = vbKeyEscape And Shift = 0 Then Unload Me

End Sub

Cheers!
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2635989
Alternatively:

Put a button on your form and set its Cancel property to true. Now, hitting the Esc key will execute the associated _click procedure.

Exit from there.

If the button must not be visible, set its left position to an appropriately large negative value and its TabStop property to false.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question