How do I cancel a Keystroke entry

I have a form opened in acformadd to add a new record.  If I accidentally press Function Key 5, all the previously entered data is cleared.

How can I prevent this?

Thanks in advance..  
Clive BeatonAccess DeveloperAsked:
Who is Participating?
Jim Dettman (Microsoft MVP/ EE MVE)Connect With a Mentor President / OwnerCommented:

  Another way to eat up keystorkes is to add an autokeys macro, define the keystorke in it, and then do nothing.

  This disables it app wide.  Finer control can be achieved as als315 said, but note that it deosn't have to be done on every control.

  You can set the forms Keyprview to true.  The form will then receive the keystroke before any control.

  So you can do this at app level, form level, or control by control.

als315Connect With a Mentor Commented:
You should use this code:
If KeyCode = 116 Then KeyCode = 0
in KeyDown event for every editable field in your form
Thanks, Jim. I always forget this opportunity.
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<Thanks, Jim. I always forget this opportunity. >>

  No problem.  Something like that is easy to forget when it's not something you use very often.   I also get caught on a lot of the new features in A2007/2010 because I simply don't use them and I answer with a 2000/2003 style answer.

  Frankly, I haven't used a lot of the new features added since 2000.  Pivot charts is a good one.  Then there's stuff that I've had routines to work with for years, such as printers, so I don't bother with the printer object introducted in 2003 for example.

  And of course as simple as it seems, Access really is a complex product and it is difficult to keep up with everything it has in there.

Clive BeatonAccess DeveloperAuthor Commented:
Thanks very much to both of you.  Hope you don't mind that I shared the points.  I worked out that you could control it at the form level, but the autokeys idea is excellent.

Thanks again.

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.