camilo_gs
asked on
Num Lock getting off by accident and creating problem in records
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.
Thanks in advance for the help.
I found the following on MSDN.Microsoft.com
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvbadev/html/chapter9retrievingsettingsysteminformation.asp
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
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvbadev/html/chapter9retrievingsettingsysteminformation.asp
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help samb39, it worked pretty well.
You can boot in the BIOS to startup with NUMLOCK on.. other than that you need to reinforce accuracy.