-
my program has about fourty text boxes. when the users presses enter, i want the focus to move to the next text box. how could i do this?? the only part i can't figure out it how to move to the next control in the tab order?
i could do it by hard coding the name of the next text box, but would like to do it by tab order.
thanks
-
-
In the KeyPress event of all forty text boxes, add:
Code:
If KeyAscii = 13 Then
KeyAscii = 0
SendKeys "{TAB}"
End If
-
-
Set the KeyPreview property of the form to true, and then use jmcswain's code in the KeyPress event of the form instead.
-
but won't that remap the Enter Key for command buttons and other controls that you might not want to remap?
-
You can use the tag property of the control to identify if the enter key behaviour for that control is to be remapped or not. The code would then look something like this:
Code:
If KeyAscii = 13 Then
If Me.ActiveControl.Tag = "" Then
KeyAscii = 0
SendKeys "{Tab}"
End If
End If
-
Damn, I should have thought of that. Nice and elegant.