Using keyboard arrow keys in combobox moves cursor to next field

B

BillD

I was given the below code to use in order to be able to enter a letter in a
combo box and then move to the next entry in the box for example I have a
combo box for states I enter M and Maine shows up in the combo box I can now
use the keyboard arrow to move to the next states with M however when I arrow
down the next state appears and the cursor moves to the next field in the
form and I have to use the up arrow to go back to the combo box. If I hit the
up arrow the previous state appears and the cursor moves to the previous
field then I have to use the down arrow to get back to the states combo box.
I am trying to find out if there is anyway to prevent the cursor from moving
out of the combo box field while using the up and down arrows (Only move
cursor with tab key or mouse)?

Any help on this will be greatly appreciated if there is anything that can
be done.

Here is the code I entered to be able to use the keyboard arrows:
Private Sub CoState_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown And ComboBox.ListIndex <> ComboBox.ListCount - 1 Then
ComboBox.ListIndex = ComboBox.ListIndex + 1
End If
If KeyCode = vbKeyUp And ComboBox.ListIndex <> -1 Then
ComboBox.ListIndex = ComboBox.ListIndex - 1
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top