How do I detect a keypress on a form?

  • Thread starter Thread starter nws
  • Start date Start date
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
 
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)
 
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.
 
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.
 
Back
Top