954,559 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

CAPS LOCK Key

Hello.

I have created a logon form in Microsoft Access and now would like the let the user know if the caps lock key is pressed. Instead of when the form is loading.... i would like a message box to display after the form has loaded and when the button is pressed,... any ideas?

Thanks,

Sam

samnicholls1987
Newbie Poster
1 post since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

I don't think VB can do that...any one of the senior techies know?

Kiba Ookami
Junior Poster in Training
66 posts since Jan 2005
Reputation Points: 10
Solved Threads: 1
 

I know nothing about VB but perhaps this could here

OurNation
Master Poster
780 posts since Aug 2004
Reputation Points: 16
Solved Threads: 9
 

This can most certainly be done in VB6, doing this in VBA (such as access, or VB within Access) on the other hand, is a whole different story.

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

Hi,

you can do this way.

Private Sub Form_KeyPress(KeyAscii As Integer)
if keyascii = 13 then 'enter key
msgbox "press enter key"
endif

End Sub

you can substitute 13 with caps lock key number

hope it help

Newvbguy

NewVBguy
Junior Poster in Training
71 posts since Mar 2005
Reputation Points: 13
Solved Threads: 3
 

Under normal circumstances, that would be great.... but trapping the enter key on keypress, and capturing the caps lock key, on keypress, are 2 entirely different subjects. The enter key is chr(13), but you could just as easily use vbenter..... anyway, that isn't the point. The cap lock key, along with a few other special keys (alt, ctrl, superL [windows key]) don't trigger the VB's Keypress event. That takes a little more work.... like use of the API (and, the bad news is, I don't believe VBA [access] allows api calls). I wrote a VB APP once, that twinkled the 3 lights.... I don't have it any more, but I know it can be done with VB6..... VBA on the other hand, I'm pretty sure not.

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

In The declaration portion of the access form (or in a module, but if it's in a module, you may need to change private to public), but in the declaration portion of the form add this:

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer 

Private Function CapsLockOn() As Boolean
    Dim xState As Integer
    xState = GetKeyState(vbKeyCapital)
    CapsLockOn = (xState = 1 Or xState = -127)
End Function


Then, (as I am not particularly familar with access, so much as VB), in one of the events, such as onload, or onclick, or whenever you want to check the value of the cap lock key, you just do a call to the function (something like this):

If CapsLockOn = True Then
    MsgBox "yup"
else
    MsgBox "Nope"
End If


I've tested this as the click event of the form in my access form, and it works for me. Let me know how it fairs for you.

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

tHAT IS P .... oops :cheesy: That is pretty dang cool!

Thanks for that - I can make good use of this one.


Cheers,


G.

GraveyDice
Newbie Poster
4 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

You're Welcome ;)

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You