Num Lock getting off by accident and creating problem in records

Posted on 2006-04-01
Last Modified: 2012-08-14
I use Microsoft Access in my business. I am having a problem with the Num lock key, it gets hit by accident and the keys on the keyboard start acting as Page Up, Down, etc which creates a problem when we are entering a new record.  For instance, I have a form to enter new Contracts, there are some fields that require numeric characters, but when the num lock key is hit by accident, and then a series of numbers are hit in the keyboard, then the form jumps to an older record, due to the num lock being off, and now this records can be changed.  For this reason the data in the older records have been changed as the employee keep hitting the numbers assuming num lock is on.  Is there any way to either make num lock always on even when the num lock key is hit, or something else that can be done within Microsoft Access?
Thanks in advance for the help.
Question by:camilo_gs
    LVL 30

    Expert Comment

    Purchase a keyboard with the numlock far away from the keypad.

    You can boot in the BIOS to startup with NUMLOCK on.. other than that you need to reinforce accuracy.
    LVL 11

    Expert Comment

    I found the following on

    Supposedly you can control the NumLock state (amongst other key states) using some Windows API calls, though in my quick tests I didn't see any useful effect.  Per the above article, the state of the keyboard is stored in an array of bytes. You retrive the array as it presently exists, set or clear the byte for a specific key, then set it back.  NumLock, CapsLock etc are supposed to be controllable in this manner. I figured you could set the flag to True in your form code module.

    Below, the relevant code.

    Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long
    Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long

    Private Sub SetKeyState(key As Integer, state As Boolean)
      Dim keys(0 To 255) As Byte
      GetKeyboardState keys(0)
      keys(key) = CByte(Abs(state))
      SetKeyboardState keys(0)
    End Sub

    My idea was to set the form's KeyPreview to True, then constantly set NumLock=true whenever a key was pressed.

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
      Call SetKeyState(vbKeyNumlock, true)
    End Sub

    Unfortunately the WinAPI call did not raise any errors but didn't seem to work, either. Maybe someone else will come up with a fix.

    -- Craig
    LVL 4

    Accepted Solution

    This guy recommends using keytweak to just map the numeric keypad keys to the keys above the letters.

    Get keytweak here:

    Author Comment

    Thanks for your help samb39, it worked pretty well.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Introduction After workin in a plethora of programming languages like C, Pro*C, ESQL/C, C++, VC++, VB, Java, HTML,JavaScipt etc, technologies and frameworks like JSP, Servlets, Struts, Spring, IBatis etc and databases like MS Access, SQLServer, Inf…
    Read about achieving the basic levels of HRIS security in the workplace.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 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

    22 Experts available now in Live!

    Get 1:1 Help Now