If you want to have the focus
move between the controls on a form when
the enter key is pressed, you can with
the SendKeys function. The basis of
the tip is to detect when the Enter key
is pressed, and then Send the Tab key to
the program.
You can detect
when the user presses enter from the
KeyPress event procedure by checking to
see if the KeyAscii parameter is the
character code 13. Then you can move the
focus to the next control in the TabIndex
order with the code:
SendKeys "{tab}"
You can move the focus to the
previous control with the code:
SendKeys "+{tab}"
This technique works with most
kinds of controls. However, it does not
work with command button controls,
because command buttons do not receive
the KeyPress event when you press enter.
Code
Sub Text1_KeyPress (KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{tab}"
KeyAscii = 0
End If
End Sub
|