Hello everyone,
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
SendKeys vbEnter
End If

Hello everyone,
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
SendKeys vbEnter
End If

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:

Hey...
The code that you have written is correct..
keyascii=13 is used for the "Enter" key response..
Instead of writin this code in the Form_load() event, write it under General Declarations..

By doing so , u r makin this code global to your form...
Let me knw... :cool:

Do you mean something like this???

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Text2.SetFocus
End Sub

Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Text1.SetFocus
End Sub

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
    Text2.SetFocus
  Else
    Text1(Index).SetFocus
  End If
End If
End Sub

Good Luck

Thank u 4 ur help, but my problem is that i have many control in my form level ,how it possible to control my form by using single line statement

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.


Good Luck

Hey...
The code that you have written is correct..
keyascii=13 is used for the "Enter" key response..
Instead of writin this code in the Form_load() event, write it under General Declarations..

By doing so , u r makin this code global to your form...
Let me knw... :cool:

But I don't see any reference to the Form_load() event in that code. Where do you get that from? :icon_wink:

But I don't see any reference to the Form_load() event in that code. Where do you get that from? :icon_wink:

M bad..woops...!!

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
End Sub


Thanks and Good Luck!...^_^...

This article has been dead for over six months. Start a new discussion instead.