Results 1 to 4 of 4

Thread: Key Pressed

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384

    Key Pressed

    On my form I have a textbox and a grid. The textbox has Tab Index 0 and Grid has Tab Index 1 (these cannot be changed). When I press tab in the textbox it automatically sends focus to the grid, however I want the code to do something when tab is pressed.
    Code I have tried:
    Code:
    Private Sub txtBox_KeyDown(KeyCode As Integer, Shift As Integer)
            
        Select Case KeyCode  
            Case vbKeyTab
                ' Do this
            Case vbKeyReturn
                ' Do this
         End Select
    Strange thing is it will go into the code if I press return but not if I press tab
    Mel

  2. #2
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    i think you would have to catch it in the keydown event, or if not then try the forms keydown event. by the time that the keypress event has fired, the tab key has been pressed and focus will be moved to the next control
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    i think you would have to catch it in the keydown event
    I am using the keydown event
    Code:
    Private Sub txtBox_KeyDown(KeyCode As Integer, Shift As Integer)
            
        Select Case KeyCode  
            Case vbKeyTab
                ' Do this
            Case vbKeyReturn
                ' Do this
         End Select
    
    End Sub
    I have tried the Form_Keydown event also but it doesn't work

    Any other suggestions?
    Mel

  4. #4
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    The Netherlands
    Posts
    403
    Just a small trick, set the property tabstop of the grid to false. Otherwise you should subclass your form and catch the Tab key.
    3rd option is to place a hook on Keyboard_LL with setwindowshook and catch VK_Tab I think.
    There are 10 types of people, those who understand binary and those who don't

    http://merlijn.beyonix.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width