i want use EnterKey in my Project ,i write some code in from load,but still TAB key use in my project. Here is a code,
If KeyAscii = 13 Then
Well the KeyAscii for the Enter key is 13 as you've stated. So why if the Enter key is pressed you are pressing it again with SendKeys?
If the Enter key is pressed then you surely want to do some other task?
It will depend on which control you are looking for the Enter key. You may have to use Me.KeyPreview = True in Form_Load to catch keystrokes.
You say the Tab key is working, don't you want the Tab key working? You can turn the Tab key off on any control look for the TabStop property. :icon_wink:
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Text2.SetFocus
Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Text1.SetFocus
or like this???
Private Sub Text1_KeyUp(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Index = Index + 1
If Index > (Text1.Count - 1) Then
'code to set focus to next control
In vb6 you can't. You can however use the tab order to specify the order of the controls as they are tabbed to. Also command buttons when you hit enter activate the click event. Then you can reduce your code for textboxes if you use arrays.
If you want to use the enter key in you project, for example there is a Log-In form, where there are "username" and "password" textboxes and an "Ok" and "Cancel" button, Then when the user presses the enter key, the Ok button must be activated or the click event of the control must be triggered.
you can set it in the property box of the control:
Default = True
but, by default it is equals to False, so you have to change it manually or make a code for it in the code window, like this:
Private Sub Form_Load()
cmdOk.Default = True