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
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
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
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
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215