Keep focus on same control after "Enter"

nschroeder

nschroeder
Local time
Today, 16:31
Joined
Jan 8, 2007
Messages
186
I found my question on a previous thread (2-21-2008), but am unable to get the answer to work for me.

I have an unbound form with several textboxes to receive search criteria (loan number or customer name), and a couple of subforms to display the requested loan and customer data. They want to key in a loan number, hit Enter, and have the focus stay in the loan number textbox, ready for the next number, but it wants to jump to the name. I tried SetFocus with no affect, so I searched your forum. The suggestion was to put

"If KeyCode = 13 Then KeyCode = 0"

in the loan number KeyDown event. However, this effectively cancels the entry. The focus stays in the textbox, but it doesn't process their request (as if they never hit Enter). I also tried setting the KeyPreview property in the Load event, but that didn't work, and I would think that wouldn't be what I want anyway, because I want the effect to apply to this control only, not the entire form.

What am I doing wrong? Thanks for your help.
 
Have you tried putting a tiny TextBox next in line in the tab order with the OnEnter event to SetFocus back to the other control? This way the user can use the mouse to move to your controls but tabbing (or enter in that control) will keep the focus on that control. You can set the width and height to 1 and the border to transparant and it is all but invisible.
 

Users who are viewing this thread

Back
Top Bottom