Results 1 to 12 of 12

Thread: Tab Key

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 1999
    Location
    India
    Posts
    73

    Post

    Hi guys
    Is there a way by which i can control the action of tab key???


  2. #2
    Junior Member
    Join Date
    Oct 1999
    Location
    Rijswijk, Holland
    Posts
    25

    Post

    Its very easy: renumber the "TabIndex" property of the parts on your window.

    Merry Christmas,

    Ingrid

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 1999
    Location
    India
    Posts
    73

    Post

    hi Ingrid
    Merry Christmas
    i didn't mean controlling using tabindex what i want to know can t tapped the tab key????? let say I have a text box text1 nd what i want is when a user presses tab key on this text box i want to raise an event.
    any idea?????


  4. #4
    Junior Member
    Join Date
    Dec 1999
    Posts
    21

    Post

    there's a couple of ways of handling this.

    One, if your tabbing into the textbox(text1), you can place your code in the the "text1_Got Focus()" procedure. If your tabbing out of the textbox when you want the code to run, use the "text1_Validate()" procedure. Hope this helps.

    Scott

  5. #5
    Guest

    Post

    From what I gather what you need is the grab the Key Press or Key Up event! I will have a play and post the code!

    ------------------

  6. #6
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = 9 Then
            MsgBox "No Tab Keys Here!"
            KeyAscii = 0
        End If
    End Sub

  7. #7
    Guest

    Post

    I am interested now! I have tried the KeyDown,KeyPress and KeyUp events none of them trigger when pressing tab! THAT SUCKS a key is being pressed!

    So if someone can help this dude out it would be interesting to see a way around this!

    Thanks

    ALF
    ALFWare

  8. #8
    Guest

    Post

    I am interested now! I have tried the KeyDown,KeyPress and KeyUp events none of them trigger when pressing tab! THAT SUCKS a key is being pressed!

    So if someone can help this dude out it would be interesting to see a way around this!

    Thanks

    ALF
    ALFWare

  9. #9
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    The code I posted worked perfectly for me, using the KeyPress event in a multiline textbox.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Apr 1999
    Location
    India
    Posts
    73

    Post

    HI
    Clunietp, your code is working becase there is only one control on the form try to put one more and then run the same code no msg will generat.
    What I have found is when have only one control then vb raise event if there is more then one control on the form vb Suppress the event and set the focus to the next control.
    so what we need to do is to stop this Suppress process so that we can control that event.
    We can do this by using lostfocus but the prob is this is raised many times and we don't have any method to know the cause of the event to manage the process.
    Thanx Manish

  11. #11
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122

    Post

    Hi,

    that's how it works: Suppose it's the Text1 control you need to trap the tab-key.

    Code:
    Private Sub Text1_GotFocus()
    
    Dim ctl As Control
    
    For Each ctl In Me.Controls
        On Error Resume Next
        ctl.TabStop = False
    Next
    
    End Sub
    
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyTab Then
            'Do whatever you want to
        End If
    End Sub
    
    Private Sub Text1_LostFocus()
    
    Dim ctl As Control
    
    For Each ctl In Me.Controls
        On Error Resume Next
        ctl.TabStop = True
    Next
    
    End Sub
    The solution is, to set the TabStop property to false for every control. The 'on error resume next' because not all controls have a TabStop property. You can build that more sophisticated, store the original value somewhere etc.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Apr 1999
    Location
    India
    Posts
    73

    Post

    I think this can solve the prob.
    thanx a lot RogerH.
    Thanx Manish

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