Control focus following "Enter" key press

GaelicFatboy

Registered User.
Local time
Today, 18:59
Joined
Apr 17, 2007
Messages
100
Would anyone be able to help with focus flow?

I've got a text box (Me.Text_PartNumber) which I'm trying to get the focus to stay with once the enter key has been pressed instead of moving to the next control in the tab index list.

Under the options menu I've set the move after enter option to 'Next field', and would prefer to keep this the same.

I've tried using:

Me.Text_PartNumber.Setfocus

But this doesn't work the focus still moves onto the next control in the tab index list.

Cheers

D
 
Each TextBox control has an "EnterKeyBehavior" property under the "Other" tab of the property sheet for the control. See if that works for you.
 
Cheers, but I'm affraid I've tried that already and it doesn't work. It just inserts a carriage return into the text being entered into the box.

D
 
Why do you want to hold the focus in this TextBox? You may need to intercept the key in the keypress event to do what you want.
 
in the afterupdate event, cant you just put

"thiscontrol".setfocus

wont that stop it going somewhere else
 
in the afterupdate event, cant you just put

"thiscontrol".setfocus

wont that stop it going somewhere else
NOPE! You could Cancel the exit event if you really need the focus to remain in that control but then you are stuck there. As I asked earlier, why do you need to keep the focus there? Perhaps there is a better way.
 
The question is, indeed, if you don't want <Enter> to move to the next control from Text_PartNumber and you don't want <Enter> to create a new line, what do you want it to do? At any rate, this will do the job:

Code:
Private Sub Text_PartNumber_KeyDown(KeyCode As Integer, Shift As Integer)
 If KeyCode = 13 Then KeyCode = 0
End Sub
 
Cheers muckers, I'll try the KeyCode method it's given me an idea.

In answer to your question as to what I'm trying to do, I've got a text box that is used to enter a part number about which various data is retrieved, but what people here tend to do is keep tapping part numbers into the text box and only now a again do they want to move onto another control. So I was aiming to use the TAB key to tab out of the part number text box and not have the ENTER key moving focus to the next control.

Once again cheers.

D
 
OK, thanks. Don't forget to turn the Form's KeyPreview on.
 
You don't need to do that for the KeyDown event in a textbox, Allan. I think that's for KeyPress/KeyDown events on the form level, like re-assigning F Keys, etc. I always have to check when I write one of these things because I can never remember, either!

Linq
 
By golly Linq, you are absolutely correct. I just tested it to make sure. Thanks.
 
Like I said, I always have to recheck it myself because I can't remember which key events require it and which don't. At 58 my old "hard drive" probably needs to be defragged; it keeps leaking data!
 

Users who are viewing this thread

Back
Top Bottom