Link to home
Start Free TrialLog in
Avatar of j777
j777

asked on

Return key using Combo box

Taking into consideration that when using a combo box, the enter key is used when making a selection from your drop down list. Our users would like to use the enter key for leaving the field. As it stands they prefer not to use the tab key, is there any way around this? Another consideration is that i am an advanced/beginner at VB6, so my understanding my be a little slower than most others in the field. Thanks for your help!!!!
jimmy
Avatar of sunil27
sunil27

You may add the following code in the KeyPress Event of the Combo box:


Private Sub Combo1_KeyPress(KeyAscii As Integer)
    '
    ' If the key pressed is Enter (KeyAscii value 13) then send the Tab key using sendkeys statement.

    If KeyAscii = 13 Then
        SendKeys "{TAB}"
    End If
       
End Sub
Avatar of j777

ASKER

very simply, it just did not work. if i understand correctly you were rerouting the keyboard but it still did not help when i hit the enter key. Again my hopes are that once you make a selection from the drop down list or manually enter the entry just by clicking the enter key will force the leaving of that field. Thank you for the help though, if you have any other suggestions please foward them to me!!
so, you want the enter key to select the highlighted item in the list, and then for the cursor to go to another control, like a textbox ??

if so, why not just use the following code (in the keypress event of the combo box):

If KeyAscii = 13 Then Text1.SetFocus

Hope this helps....

SiM99
You can use the trick below :

Private Sub Form_Load()

    Me.KeyPreview = True
   
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

    If KeyCode = 13 Then
        SendKeys "{Tab}", True
    End If
   
End Sub
private_sub combo1_Change()
'On change ie when the enter is pressed and a selection is made

  text1.setfocus

end sub

the above will work if and only if u have set the "Default" to false on any command button, cos if u have a command button with default set to 'true' when enter is pressed that command  button is triggered by default

Hope this helps... as the info u are asking for is not terribly clear

ChaseZero
Avatar of j777

ASKER

i am sorry if i did not make my situation clear. As it stands using the enter key the way a combo box has intended works properly. The problem is that the user wants,(for a lack of better explanation), to have the enter key have a dual function. The main function would be to use the enter key as if the combo box was not on the form at all, anotherwords just go to the next field, as well as the normal functionality it already has with the combo box.
set formname.keypreview = true (in the form properties, not through code)

then, you can use form_keypress and check for keyascii 13 to carry out whatever code you wish.

By the way... what exactly would the form do when the combo box is not there ?
Avatar of j777

ASKER

I have actually tried this to no avail. It seems that with the combo box on the form the enter key is only recognized for its' use within the combo box limitations. The reason for the combo box is that i am populating it with a sybase list of project numbers. But the user needs to be able to manually enter a project number then hit the enter key to leave the field and do the next retreive.
ASKER CERTIFIED SOLUTION
Avatar of paul_tsekov
paul_tsekov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial