-
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.
-
Set all other TabStop to False.
You'll have to use the mouse to focus on another control.
SamT
-
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
-
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
-
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
-
Forum Rules