Esc button problem

Hi Experts,

I want to use something like this in the form
KeyDown event:

If KeyCode = vbEsc Then
MsgBox "It works!"
End if


But this is not enought
Dim KeyCode as ?????

I dont know, please help me....
BootyAsked:
Who is Participating?
 
TrygveConnect With a Mentor Commented:
A small error in the ESC-constant. Try this

    If KeyCode = vbKeyEscape Then
        MsgBox ("It works !")
    End If

It worked in my test application. Have a look in the help file for Keycode Constants for other usefull constants.

Trygve
0
 
BootyAuthor Commented:
Hi Trygve,
It worked fine but how do I use this
in the KeyPress event ?

Error at the word KeyCode...

Regards
0
 
TrygveCommented:
Can't you use the KeyDown event ? That was what you asked for...

For KeyPressed event:

    If KeyAscii = vbKeyEscape Then
        MsgBox ("Hei")
    End If


From help: "To make sure a form receives all keyboard events, even those that occur for controls, before they occur for the controls, set the KeyPreview property of the form to Yes."


Generally: Look at the parameters in the sub header and read the help file for examples on how to use the functions, events etc.
0
 
BootyAuthor Commented:
Hi Trygve,

Yes I asked for KeyDown and then for
KeyPress .
Two answers for 5 points...sorry :-)

Thanks.
0
 
TrygveCommented:
No problem !

Have a nice day !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.