Consulting

Results 1 to 5 of 5

Thread: Solved: Set focus on a control

  1. #1
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location

    Solved: Set focus on a control

    I have a form (basically is a search form), with a Textbox and several other controls. What I would like to do is set the focus to the Textbox and select the entire content everytime I hit the enter key. I tried using the .SetFocus but it is not working - so to speak. If I were to click a button, the focus is then set to the Textbox, but if I hit the Enter key, the focus is set to next tab index! Because it is a search form, the Textbox would the the most ideal to have the focus all the time. I don't know if this makes a difference or not, I have a KeyDown event on my Textbox, to process the Enter Key.

    Thanks in advance.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Set all other TabStop to False.

    You'll have to use the mouse to focus on another control.

    SamT

  3. #3
    VBAX Tutor Philcjr's Avatar
    Joined
    Jul 2005
    Location
    Bedminster, NJ
    Posts
    208
    Location
    What I would try is:

    1) "setFocus" to your texbox

    2) In "UserForm_Initialize" routine put CommandButton1.Enabled = True... when you hit the "enter" key, the command button will trigger

    Phil

  4. #4
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Thank you both. The solutions work. Phil's much simpler to implement and more desirable. However, I think that you had made a mistake. It should be CommandButton1.Default = True. Nevertheless, thank you for your solutions

  5. #5
    VBAX Tutor Philcjr's Avatar
    Joined
    Jul 2005
    Location
    Bedminster, NJ
    Posts
    208
    Location
    Jkwan, glad it is working for you... oppps, I guess next time I shouldn't be yapping on the phone while posting

Posting Permissions

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