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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Turn NUMLOCK on/off

Status
Not open for further replies.

CarlyA

Programmer
Jul 14, 2000
15
0
0
US
I have been working with VBA to set the NUMLOCK to &quot;on&quot; when certain forms are activated/opened. I'm not having any luck. I'm trying to work with a database developed years ago by programmers who are since long gone from the company.&nbsp;&nbsp;It looks like they have code somewhere (I can't find it) that is constantly resetting the numlock to off.<br><br>If anyone can help me, I'd appreciate it.<br>Thanks
 
Hi<br><br>Try the following in the Form_Open-Sub:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;<FONT FACE=monospace>Sendkeys &quot;{NUMLOCK}&quot;, true</font><br><br>I think it will work<br>ollie
 
Maybe the following API function and code will help you.<br>This can be used to turn Cap Locks on and off also by changing the code according to the comment lines 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>Hope this helps you,<br>RDH <p>Ricky Hicks<br><a href=mailto: rdhicks@mindspring.com> rdhicks@mindspring.com</a><br><a href= > </a><br>
 
Thank you for the help you guys.&nbsp;&nbsp;There is something strange in this database.&nbsp;&nbsp;When I used Ricky's code, I saw the numlock led flicker on my keyboard.&nbsp;&nbsp;It didn't when I tried Ollie's code but I'm confident the problem does not lie within the code but within the db.&nbsp;&nbsp;It's obvious there is code somewhere in this database that is cancelling the numlock code but I can't locate it --- yet!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top