Results 1 to 5 of 5

Thread: Same problem with Tab

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Chennai,India
    Posts
    7
    Works fine with one control, but thats not what i want.
    Is there any other way out where there are more controls.
    !@#$%

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    hmmm... you know theres a post with the same question 1 post below yours huh?!
    so why don't wait for anyone to answer there?
    hmmkay

    http://209.207.250.147/showthread.ph...467#post172467

    In case you're lazy:
    Code:
    'Set all the tabstop of all controls to false
    Private Declare Function GetFocus Lib "user32" () As Long
    Private Sub Form_KeyPress(KeyAscii As Integer)
    Dim h&
    If KeyAscii = vbKeyTab Then 'vbKeyTab = ASCII char 9, but constants look better imho (in my humble opinion )
        h = GetFocus 'gets the handle of the control in focus.
        If h = Text1.hWnd Then MsgBox "TAB AT TEXT1" 'reminds you that text1 has focus.
            Text2.SetFocus 'then move on to the next control, just as normal.
    End If
    End Sub
    
    Private Sub Form_Load()
    KeyPreview = True 'receive all keystrokes before the controls do (sort of subclassing, but then easy )
    End Sub
    Here's a modified one for ya, in case you're extremely lazy (without comments ok? )

    Code:
    'This example uses 2 textboxes, both with tabstop to false.
    Private Declare Function GetFocus Lib "user32" () As Long
    Private Sub Form_KeyPress(KeyAscii As Integer)
    Dim h&
    If KeyAscii = vbKeyTab Then
        h = GetFocus
        If h = Text1.hWnd Then
            MsgBox "TAB AT TEXT1"
            Text2.SetFocus
        ElseIf h = Text2.hWnd Then
            MsgBox "TAB AT TEXT2"
            Text1.SetFocus
        End If
    End If
    End Sub
    
    Private Sub Form_Load()
    KeyPreview = True
    End Sub


    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3
    Addicted Member
    Join Date
    Oct 2000
    Posts
    208

    Still not working for me

    Jop --

    Maybe I'm really missing something, but I still can't get Form_Keypress to fire when hitting a tab. I tried your code but it's not working.

    Any suggestions?

    Elizabeth

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Did you set all the control's tabstop to false?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    Addicted Member
    Join Date
    Oct 2000
    Posts
    208
    Jop --

    Bear with me, I'm just a beginner.

    The form has at least 100 controls. I worry that if I take out the tab stops, won't I have to hard-code the tab order if I use the method you suggest? Or am I missing something?

    Let me try just a bit to describe my situation a bit more.

    I have a form with four frames in it (well, there are more, but four major ones). These have tabs associated with them, so the user can click on the tabs to access the four frames.

    It's used for data entry, and also used for updating old entries.

    I'd like the user to be able to tab through the first frame, and when on the last textbox, to be able to hit tab and be automatically sent to the next frame.

    I thought I could do this by detecting a tab in the last textbox, and trigger appropriate code to send the user to the next frame. (and, also, if the user hits shift-tab in the first textbox, to send him back a frame).

    I've tried keypress, keydown, and keyup, and can't get any of them to detect tab.

    I'm working on a solution with invisible command buttons which, when they get the focus, automatically kick the user to the next frame. But a few problems starting cropping up with this approach; I'll be working on it more on Monday to see if I can make this approach work.

    But if there's some way I can detect tab when the user is on the last textbox on the frame, well, that would be ideal.

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