Return key using Combo box

Posted on 2000-01-17
Medium Priority
Last Modified: 2010-05-02
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!!!!
Question by:j777

Expert Comment

ID: 2360768
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

Author Comment

ID: 2362550
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!!

Expert Comment

ID: 2363503
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....

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.


Expert Comment

ID: 2363585
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

Expert Comment

ID: 2363603
private_sub combo1_Change()
'On change ie when the enter is pressed and a selection is made


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


Author Comment

ID: 2363978
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.

Expert Comment

ID: 2364090
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 ?

Author Comment

ID: 2364131
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.

Accepted Solution

paul_tsekov earned 100 total points
ID: 2364959
Hi i777,
  I had the same problem.
  I wanted to use the <Enter> key to
 make the focus go to the next control,
but it showed me the drop-down list.

 so, how did I solve it?

 I just use the arrow UP and arrow DOWN
keys for changing the focus.
  I made the Enter change the focus on each control , except the ComboBox.

   So, that it all the controls change the focus by ARROWS and ENTER.
   Only in ComboBox change the focus
only with ARROWS.

  To change the focus with arrows you
should use the Key_Down or the Key_up events.
 So here is some code that could be useful to you:

Private Sub Text2_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)

Select Case KeyCode
Case vbKeyDown
Case vbKeyUp
End Select      

End Sub

  So , remember there is no real solution to your problem.
  You must choose between showing the Drop-Down list or changing the focus.!!!!!!

       Pavel Tsekov
     email : paul_tsekov@yahoo.com


Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question