SOLUTION NEEDED FOR ACCESS 2003 / VBA, NOT FOR ANY VERSION OF VB.
I need to differentiate between the Enter key on the main keyboard and
the numeric keypad and obviously tried using vbkeySeparator in the
form’s Keypress event. However, both Enter keys return KeyCode 13.
MS Q188550 (below) offers a workaround for VB only – it does not claim
to fix VBA. On this basis you might expect that the bug is fixed in
Access/VBA but it isn’t. I have tried the fix in VB and it works fine,
but including the code in an Access 2003 form doesn’t work – the call
to PeekMessage always returns zero. I’ve also tried various different
values for the filter to no good effect.
Many thanks for you help
Dave
- this is the VB fix cribbed straight from the Microsoft knowledge
base...
Private Declare Function PeekMessage Lib "user32" Alias _
"PeekMessageA" (lpMsg As MSG, ByVal hwnd As Long, _
ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, _
ByVal wRemoveMsg As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type MSG
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Const PM_NOREMOVE = &H0
Const WM_KEYDOWN = &H100
Const WM_KEYUP = &H101
Const VK_RETURN = &HD
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim MyMsg As MSG, RetVal As Long
' pass:
' MSG structure to receive message information
' my window handle
' low and high filter of 0, 0 to trap all messages
' PM_NOREMOVE to leave the keystroke in the message queue
' use PM_REMOVE (1) to remove it
RetVal = PeekMessage(MyMsg, Me.hwnd, 0, 0, PM_NOREMOVE)
' now, per Q77550, you should look for a MSG.wParam of VK_RETURN
' if this was the keystroke, then test bit 24 of the lparam - if
ON,
' then keypad was used, otherwise, keyboard was used
If RetVal <0 Then
If MyMsg.wParam = VK_RETURN Then
If MyMsg.lParam And &H1000000 Then
MsgBox "Enter from Keypad pressed"
Else
MsgBox "Enter from Keyboard pressed"
End If
End If
Else
MsgBox "No message waiting, or possible problems calling
PeekMessage"
End If
End Sub