On Key Press not working in Access 2003?

  • Thread starter Thread starter Onno Willems
  • Start date Start date
O

Onno Willems

Hi,

I have a form with an "On Key Press" method in which I check if the key
pressed is escape and close the form if so. This was created in Access
2002/XP and works fine.

If I make a new similar form in Access 2003, I cannot get this to work, the
OnKeyPress method is not called at all. Even copying the old (working form)
to a new one in Access 2003 doesn't work, the OnKeyPress method of the form
just doesn't get called at all! (while the OnKeyPress from the form created
in Access XP that is stored in the same database works just fine).

Am I missing something here, or is there a bug in Access 2003?

Thanks,
Onno
The Netherlands
 
Is the Key Preview property of the form set to 'Yes'? With Key Preview set
to 'Yes' (True if you set it in code) the following works for me in Access
2003 ...

Private Sub Form_KeyPress(KeyAscii As Integer)

If KeyAscii = 27 Then
DoCmd.Close acForm, Me.Name
End If

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Oops, overlooked that! Turned Key Preview on and it worked again like it
used to.

One problem donwn, a few more to go.

Many thanks!
Onno
 
Back
Top