11 November 2022

MS Access VBA Bug - Numlock key keeps turning off with SendKeys

The SendKeys() function that is built-in VBA has really a side effect that causes NumLock to be deactivated.
But you can use a workaround and call another implementation of the same function that is a part of WScript component (a part of Windows operating system).

If you create a new Sub with the same name, it shadows the "system" SendKeys:
Public Sub SendKeys(pString, Optional pWait As Boolean = True)
   
    '-- There is a well known bug in all versions of Access involving SendKeys switching off the Numlock key.
    Dim WshShell

    Set WshShell = CreateObject("WScript.Shell")
    WshShell.SendKeys pString, pWait
    Set WshShell = Nothing

End Sub
https://stackoverflow.com/questions/25977933/sendkeys-is-messing-with-my-numlock-key-via-vba-code-in-access-form