Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NumLock on/off in VBA

Status
Not open for further replies.

Warrior

Programmer
Apr 14, 2000
9
NL
hello everyone,<br><br>how do i switch numlock on when loading a form in access<br>my idea is such as &quot;set numlock is true&quot;but it ain't working <br>does anyone know how this is done<br><br>thanks for any help
 
The following API function will do what you want. It can also be used for the Cap Locks with a few changes that are documented in the code:<br><br>'*********************************************<br>'Windows API/Global Declarations for :NumLock<br>'*********************************************<br><br>'Public Const VK_CAPLOCK = &H14<br>Public Const VK_NUMLOCK = &H90<br><br>Public Type KeyboardBytes<br>kbByte(0 To 255) As Byte<br>End Type<br>Public kbArray As KeyboardBytes<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>Public Declare Function GetKeyState Lib &quot;user32&quot; _<br>(ByVal nVirtKey As Long) As Long<br>Public Declare Function GetKeyboardState Lib &quot;user32&quot; _<br>(kbArray As KeyboardBytes) As Long<br>Public Declare Function SetKeyboardState Lib &quot;user32&quot; _<br>(kbArray As KeyboardBytes) As Long<br><br>'********************************************<br>'Add the following code to the form<br>'to change to CapLocks change VK_NUMLOCK to VK_CAPLOCK<br>'********************************************<br>Private Function NumLock() As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NumLock = GetKeyState(VK_NUMLOCK) And 1 = 1<br>End Function<br><br>Private Sub Form_Load()<br>GetKeyboardState kbArray<br>kbArray.kbByte(VK_NUMLOCK) = 1<br>SetKeyboardState kbArray<br>End Sub<br><br>HTH<br>RDH <p>Ricky Hicks<br><a href=mailto: rdhicks@mindspring.com> rdhicks@mindspring.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top