Solved

Unload form just by pressing 'Escape' key

Posted on 2000-03-20
5
216 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 25 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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
A macro to Count the number of rows across all worksheets 3 151
using Access 8 85
vb6 connector to SQL Server 2 42
MsgBox 4 71
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 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