Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Turn NUMLOCK on/off

Turn NUMLOCK on/off

Turn NUMLOCK on/off

I have been working with VBA to set the NUMLOCK to "on" 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.  It looks like they have code somewhere (I can't find it) that is constantly resetting the numlock to off.

If anyone can help me, I'd appreciate it.

RE: Turn NUMLOCK on/off


Try the following in the Form_Open-Sub:

    Sendkeys "{NUMLOCK}", true

I think it will work

RE: Turn NUMLOCK on/off

Maybe the following API function and code will help you.
This can be used to turn Cap Locks on and off also by changing the code according to the comment lines in the code.

'Windows API/Global Declarations for :NumLock

'Public Const VK_CAPLOCK = &H14
Public Const VK_NUMLOCK = &H90

Public Type KeyboardBytes
kbByte(0 To 255) As Byte
End Type
Public kbArray As KeyboardBytes
Public Declare Function GetKeyState Lib "user32" _
(ByVal nVirtKey As Long) As Long
Public Declare Function GetKeyboardState Lib "user32" _
(kbArray As KeyboardBytes) As Long
Public Declare Function SetKeyboardState Lib "user32" _
(kbArray As KeyboardBytes) As Long

'Add the following code to the form
'to change to CapLocks change VK_NUMLOCK to VK_CAPLOCK
Private Function NumLock() As Integer
        NumLock = GetKeyState(VK_NUMLOCK) And 1 = 1
End Function

Private Sub Form_Load()
GetKeyboardState kbArray
kbArray.kbByte(VK_NUMLOCK) = 1
SetKeyboardState kbArray
End Sub

Hope this helps you,

Ricky Hicks

RE: Turn NUMLOCK on/off

Thank you for the help you guys.  There is something strange in this database.  When I used Ricky's code, I saw the numlock led flicker on my keyboard.  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.  It's obvious there is code somewhere in this database that is cancelling the numlock code but I can't locate it --- yet!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close