How do I cancel a Keystroke entry

Posted on 2011-10-29
Last Modified: 2012-05-12
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..  
Question by:CRB1609
    LVL 39

    Assisted Solution

    You should use this code:
    If KeyCode = 116 Then KeyCode = 0
    in KeyDown event for every editable field in your form
    LVL 56

    Accepted Solution


      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.

    LVL 39

    Expert Comment

    Thanks, Jim. I always forget this opportunity.
    LVL 56

    Expert Comment

    by:Jim Dettman (Microsoft MVP/ EE MVE)
    <<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.


    Author Closing Comment

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    This isn't a frequent question on EE. I must have seen it three or four times (among several thousand questions). However, I use this trick quite often, most frequently as a delayed Current event. A form does not expose it's calculation dependenc…
    Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now