Results 1 to 8 of 8

Thread: Focus Question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    217
    my program has about fourty text boxes. when the users presses enter, i want the focus to move to the next text box. how could i do this?? the only part i can't figure out it how to move to the next control in the tab order?
    i could do it by hard coding the name of the next text box, but would like to do it by tab order.
    thanks

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Maybe this helps you.
    Code:
    SendKeys "{TAB}"
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  3. #3
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    In the KeyPress event of all forty text boxes, add:

    Code:
    If KeyAscii = 13 Then
        KeyAscii = 0
        SendKeys "{TAB}"
    End If

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    217

    Talking

    Perfect...thanks you

  5. #5
    Addicted Member
    Join Date
    Sep 2000
    Posts
    219

    Talking

    Set the KeyPreview property of the form to true, and then use jmcswain's code in the KeyPress event of the form instead.

  6. #6
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    but won't that remap the Enter Key for command buttons and other controls that you might not want to remap?

  7. #7
    Addicted Member
    Join Date
    Sep 2000
    Posts
    219
    You can use the tag property of the control to identify if the enter key behaviour for that control is to be remapped or not. The code would then look something like this:

    Code:
    If KeyAscii = 13 Then
        If Me.ActiveControl.Tag = "" Then
            KeyAscii = 0
            SendKeys "{Tab}"
        End If
    End If

  8. #8
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    Damn, I should have thought of that. Nice and elegant.

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