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

Recommended Answers

All 8 Replies

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

I know nothing about VB but perhaps this could here

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.

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

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.

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.

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

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


Cheers,


G.

You're Welcome ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.