KeyCode with Shift

seeker63a

Registered User.
Local time
Yesterday, 23:54
Joined
Mar 30, 2014
Messages
16
I have used:

Select Case KeyCode
Case vbKeyEnter and Shift = acCtrlMask
some code

and when I run the program KeyCode = 17 or vbKeyCtrl thus not entering the case statement

I have done:
if KeyCode = vbKeyEnter then
if Shift = acCtrlMask then
some code
end if
end if

with the same result KeyCode is 17. So how is the correct way to write vba code so that something happens when Ctrl+Enter is used.
 
The below code does it!
Code:
  If (Shift And acCtrlMask) And KeyCode = 13 Then
    MsgBox ("<Ctrl> and <Enter> is pressed!")
  End If
 
When I run this KeyCode is 17 which is passed to the KeyDown method. That is the problem how do I make key combinations work. because the first key pressed is ctrl key which is 17:banghead:
 
Have you even tried my code, (I don't think so)?
Because when I have the below code in a text control's KeyDown event it is executing perfect, (msgbox only shows when both <Ctrl> and <Enter> is pressed.

Code:
Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)
  If (Shift And acCtrlMask) And KeyCode = 13 Then
    MsgBox ("<Ctrl> and <Enter> is pressed!")
  End If
End Sub
attachment.php
 

Attachments

  • Keycode.jpg
    Keycode.jpg
    10.4 KB · Views: 1,834
Thanks for your expertise. It turns out that the above code needed to be the first line of the event.
 

Users who are viewing this thread

Back
Top Bottom