number lock turns off intermittently

Ken Sheridan helped me with this code some time back and it worked except it kept turning off the numlock. Searching google I found the adding the sendkey should correct the problem. (Said something about a glitch in access). Now it works sometime but I still randomly get the numlock turned off.

Any ideas as to why and how to correct it

thanks

Private Sub Form_Load()
DoCmd.GoToRecord acDataForm, "frmInput", acNewRec
Me.OpenDate.SetFocus
With Me.ActiveControl
        .SelLength = 0
        .SelStart = Len(.Text)
        If Not IsNull(.Value) Then
            If TimeValue(.Text) = 0 Then
                SendKeys " "
                SendKeys "{Numlock}", True
            End If
        End If
    End With
End Sub

* Please try a lower page number.

* Please enter only numbers.

* Please try a lower page number.

* Please enter only numbers.

You could try calling the Windows API to check if the NumLock key is currently turned off.  Add this little module to the database, or incorporate the code in any existing module you have which calls the API:

Option Compare Database
Option Explicit

Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Const VK_NUMLOCK = &H90

Public Sub TurnOnNumLock()

    If GetKeyState(VK_NUMLOCK) <> 1 Then
        SendKeys "{Numlock}", True
    End If

End Sub

You then just have to put the line:

    TurnOnNumLock

at the end of the procedure before the End Sub line instead of conditionally calling the SendKeys statement within the If….End If constructs.  If NumLock is turned on it won't do anything. if it's turned off it will turn it back on again.

_____________________
Ken Sheridan,
Newport, Shropshire, England

"Don't write it down until you understand it!" - Richard Feynman

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

ciao jw57fd,

here :

http://access.mvps.org/access/api/api0046.htm

you can find a solution which avoids sendkeys involving also capsLock and crollLock.

HTH,

ciao, Sandro.

ps. remember to apply API manipulation to allow it works with Office 64 bit if needed.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

hello Ken,

I added this to my event procedure right at the beginning

Option Compare Database
Option Explicit

Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Const VK_NUMLOCK = &H90 (this is red and I know that's not good)

_______________________________________________________________________________________________________

Public Sub TurnOnNumLock()

    If GetKeyState(VK_NUMLOCK) <> 1 Then
        SendKeys "{Numlock}", True
    End If

End Sub

    TurnOnNumLock

and when I close the editor I get an error message :

the expression On Current you entered as the event property setting produced the following error: Constants, fixed-length strings, arrays, user-defined types and Declared statements not allowed as Public members of object modules.

I don't know what that means but I assume I have this expression in the wrong place. I just don't know where to put it.

thanks

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

The statement 

    TurnOnNumlock

 

Must be inside a procedure in order to work. That is,

 

Function yourFunction() as Boolean

 

   Your code

 

    TurnOnNumlock

End Function

 

Author of The Ten Commandments Of VBA For Microsoft Access Newbies

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

The code I gave is that for a standard module.  To create this, open the VBA editor and select Module in the Insert menu on the VBA menu bar.  In the new module paste the code I gave you in place of whatever is there.  Save the module as mdlNumlockStuff for instance.

Then in the form's Load event procedure, after the code to set focus to the OpenDate control and position the insertion point at the end of its contents put the single line:

   TurnOnNumLock

_____________________
Ken Sheridan,
Newport, Shropshire, England

"Don't write it down until you understand it!" - Richard Feynman

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

hello ken,

 I mad a module and names it mdlNumLockStuff. Here is the module:

Option Compare Database

Option Explicit

Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Const VK_NUMLOCK = &H90

Public Sub TurnOnNumLock()

    If GetKeyState(VK_NUMLOCK) <> 1 Then
        SendKeys "{Numlock}", True
    End If

End Sub

In the On Load event procedure I have:

Private Sub Form_Load()
DoCmd.GoToRecord acDataForm, "frmInput", acNewRec
Me.OpenDate.SetFocus
TurnOnNumLock
End Sub

but I still have the numlock turned off about half the time.

As always thanks for your help

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

....................but I still have the numlock turned off about half the time.

I'm afraid that I can't offer any explanation for that.

_____________________
Ken Sheridan,
Newport, Shropshire, England

"Don't write it down until you understand it!" - Richard Feynman

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

I had this problem and realized it was the SendKeys that was triggering it.  Once, I exchanged the SendKeys line for a *proper* line on said Form it stayed on.  Could this be what is happening to you?
Gina Whipp
Microsoft MVP (Access 2010-2015)
https://www.access-diva.com/tips.html

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

thanks for the reply.

What do you mean by a *proper* line?

I don't even remember what I had to start with but the numlock  on was hit or miss. Then I did a google search and found that this is an access issue and the sendkey line was the solution. It wasn't, and with a little more searching ( well a lot more) I found the send key wasn't the answer and it causes more problems. So here I am.

thanks for the help 

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

A DoCmd.RunCommand line instead of SendKeys,  Mine was also hit or miss as some Users reported an issue while others did not.  Once the line was replaced no one experienced the issue.
Gina Whipp
Microsoft MVP (Access 2010-2015)
https://www.access-diva.com/tips.html

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

* Please try a lower page number.

* Please enter only numbers.

* Please try a lower page number.

* Please enter only numbers.

 
 

Question Info


Last updated October 5, 2021 Views 2,800 Applies to: