Solved

Unload form just by pressing 'Escape' key

Posted on 2000-03-20
5
211 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best way to parse out a json string in VB6? 10 171
Prevent user closing word document opened with VB6 6 74
Problem to With line 4 57
VB6 - Scroll Mouse wheel on Picturebox 13 44
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 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