How to prevent users from typing values in combo box (1 Viewer)

tkatende

New member
Local time
Yesterday, 21:43
Joined
Apr 26, 2009
Messages
4
Hello there,
I need some help on how to prevent users from typing values into the combo box other than those listed by the combo box drop down menu.[I would like to have this done for purposes of consistence in the data]
Thanks
Timothy
 

missinglinq

AWF VIP
Local time
Today, 00:43
Joined
Jun 20, 2003
Messages
6,423
Another approach would be to simply not let them enter anything into the combobox, rather than throwing up a flag after they've done so, as Limit to List will do:

Code:
Private Sub ComboBoxName_KeyDown(KeyCode As Integer, Shift As Integer)
 If KeyCode <> vbKeyTab And KeyCode <> vbKeyReturn Then KeyCode = 0
End Sub

Or warn the user as soon as they attempt to enter new data:

Code:
Private Sub ComboBoxName_KeyDown(KeyCode As Integer, Shift As Integer)
 Select Case KeyCode
 Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp
  'Do nothing
 Case Else
  KeyCode = 0
  MsgBox "You must select a value from the dropdown!" & vbNewLine & vbNewLine & "       You cannot enter new data here!"
 End Select
End Sub
 
Last edited:

Dhalsim

New member
Local time
Yesterday, 21:43
Joined
Jul 9, 2013
Messages
8
Hello

Is there a way to modify this bit of code to allow alphabet keystrokes to jump down the combox list. e.g hit "J" and go to first J in list.

Private Sub ComboBoxName_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode <> vbKeyTab And KeyCode <> vbKeyReturn Then KeyCode = 0
End Sub

Cheers
 

missinglinq

AWF VIP
Local time
Today, 00:43
Joined
Jun 20, 2003
Messages
6,423
Maybe I'm misreading your post, but if you're talking about hitting a given letter and having it scroll down to the first entry starting with that letter, not really. That's the default behavior (with Auto Expand set to Yes) but users cam either type into the Control, or using the above code, cannot type into the Control.

Linq ;0)>
 

Dhalsim

New member
Local time
Yesterday, 21:43
Joined
Jul 9, 2013
Messages
8
yeah that's what I meant. Thanks for the reply.
 

Users who are viewing this thread

Top Bottom