By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,560 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,560 IT Pros & Developers. It's quick & easy.

Using Arrow Keys in Combo Box

tdw
100+
P: 206
Hi,

Is there a way to program the down arrow key on the keyboard to move to the next item in a combo box list?

The reason I want to do this is that my "Ordered By" combo box on my form is populated by a Customers table. Some of the companies in our customers list have multiple offices, each of which counts as a separate customer. For Example "RGS Tile, LLC" has offices in Arlington, Lake Ridge, Fredericksburg, etc. So in the combo box they are listed as "RGS Title, LLC (Arlington)", "RGS Title, LLC (Lake Ridge), etc.

The autocomplete feature fills in the first customer in the list alphabetically, so for example, when I type "RG" that is enough to cause "RGS Title, LLC (Arlington)" to pop up. However, the RGS office in Lake Ridge is our most frequent customer. So I find myself needing to frequently highlight the "(Arlington)" portion of the text to change it to "(Lake Ridge)"

I would like to be able to type "RG", let it pop up, then hit the down key a couple times until "RGS Title, LLC (Lake Ridge)" shows up. I don't want to have to use the drop-down, and I don't want to have to do the mouse highlight/type over thing every time. It's too tedious.

Thanks
Aug 11 '08 #1
Share this Question
Share on Google+
4 Replies


missinglinq
Expert 2.5K+
P: 3,532
I wrote this for someone who had a similar requirement. Just replace all instances of YourComboBox with the actual name of your cbo.

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourComboBox_KeyDown(KeyCode As Integer, Shift As Integer)
  2.  
  3.   Select Case KeyCode
  4.     Case vbKeyDown
  5.       If YourComboBox.ListIndex <> YourComboBox.ListCount - 1 Then
  6.         YourComboBox.ListIndex = YourComboBox.ListIndex + 1
  7.       Else
  8.         YourComboBox.ListIndex = 0
  9.       End If
  10.    Case vbKeyUp
  11.       If YourComboBox.ListIndex <> 0 Then
  12.         YourComboBox.ListIndex = YourComboBox.ListIndex - 1
  13.       Else
  14.         YourComboBox.ListIndex = YourComboBox.ListCount - 1
  15.       End If
  16. End Select
  17.  
  18. End Sub
  19.  
  20.  
In order to keep focus from leaving the combobox when you get to the beginning or the end of the selections, I have it "wrapping." If you get to the last selection and hit the Down Arrow again, it wraps back to the first selection ; if you're on the first selection and hit the Up Arrow it wraps around to the last selection.

From your post, it would appear that you reside in the historical Commonwealth of Virgina! If so, which part?

Linq ;0)>
Aug 11 '08 #2

tdw
100+
P: 206
tdw
This sounds perfect. Thanks!

Woodbridge, Virginia
Aug 11 '08 #3

P: 1
(i'm only a beginner, and not trained as a programmer - i'm an industrial engineer, but here was my solution to the same question, only found it a different way). it allows you to use the combo box similar to the way google's home page does - you can start typing till it finds what u want

In the properties for the combo box, under the GotFocus, add an event procedure, using the code below. just replace the "cboYourName" with your combo box's name



Private Sub cboYourName_GotFocus()

cboYourName.Dropdown

End Sub
Nov 6 '08 #4

missinglinq
Expert 2.5K+
P: 3,532
If you read the original post carefully, you'll see that the OP stated

I don't want to have to use the drop-down, and I don't want to have to do the mouse highlight/type over thing every time. It's too tedious.
Alternate solutions are always welcome here, but please make sure that they fulfill the stated needs of the original poster.

Welcome to Bytes!

Linq ;0)>

Moderator
Nov 7 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.