View Full Version : Solved: Set focus on a control
JKwan
02-17-2010, 08:40 AM
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
Philcjr
02-17-2010, 09:56 AM
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
JKwan
02-17-2010, 10:54 AM
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
Philcjr
02-17-2010, 11:11 AM
Jkwan, glad it is working for you... oppps, I guess next time I shouldn't be yapping on the phone while posting :doh:
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.