How do I detect a keypress on a form?

N

nws

How do I detect a keypress on my form?

I tried using the following code, but it didn't work. Am I
missing something?

Private Sub Form_KeyPress(KeyAscii As Integer)
MsgBox(KeyAscii)
End Sub
 
A

Al Camp

Set KeyPreview to Yes
Use this "non-parentheses" MsgBox...
MsgBox "Ascii = " & KeyAscii, vbOKOnly

Note:
The "parenthesis type" MsgBox requires an expression...
Dim Response as String
Response = MsgBox(Prompt,Buttons,Title)
 
N

nws

You guys are the best! That really helped me out!

But I can't use the Function keys like I had originally intended
to do. Is there an easy way for me to use the Function keys
like F1 instead of it bringing up the Access help? If not then
I'll just use some other keys.
 
N

nws

Sorry, I left out a piece of info..... I can get the function
buttons to "sort of" work by using KeyDown, but it still
brings up the "help" files when I use F1. Any way to
make F1 not bring up the help files? Same with the
other function keys.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top