Handle Ctrl key and Enter Key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mohanty2050
    New Member
    • Apr 2010
    • 7

    #1

    Handle Ctrl key and Enter Key

    I want to focus another control when I press both Ctrl key and Enter Key in a text box. How can I do this?
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    This code jumps to Command3 if CTRL and ENTER are pressed in Text1.

    Code:
    Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
       If KeyCode = vbKeyReturn And Shift = 2 Then
          Command3.SetFocus
       End If
    End Sub

    Comment

    • mohanty2050
      New Member
      • Apr 2010
      • 7

      #3
      Originally posted by ggeu
      This code jumps to Command3 if CTRL and ENTER are pressed in Text1.

      Code:
      Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
         If KeyCode = vbKeyReturn And Shift = 2 Then
            Command3.SetFocus
         End If
      End Sub
      How can I use this code in Text1_KeyPress( ) event?

      Comment

      • Guido Geurs
        Recognized Expert Contributor
        • Oct 2009
        • 767

        #4
        You can't use this with Keypress because it controls only on 1 key= KeyAscii
        Private Sub Text1_KeyPress( KeyAscii As Integer)

        Comment

        Working...