Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allow only Combo Values to be typed in a Combo Box

Status
Not open for further replies.

Timinator

Programmer
Apr 13, 2001
33
US
Does anyone know a quick setting or piece of code to limit an entry in a combo box to an item that is in the list? I need the user to be able to type in the box so i need to use the combo drop down, but i don't want them to be able to type values that are not in the combo box. Thanks.

Tim
 
There is a combobox property titled Limit to List. Set it to yes.
 
ehm...where you have seen this property? I know it in Access...but in VB I never saw it.
Timinator, you've tried OnChange event to search the list for a matching value? Stevie B. Gibson
 
I know that Limit to List property works in Access, but I can't find how to turn that on in Visual Basic.
 
try this:

Private Sub Combo1_LostFocus()
Dim i As Integer
Dim Found As Boolean
For i = 0 To Combo1.ListCount
If UCase(Combo1.List(i)) = UCase(Combo1.Text) Then
Found = True
Exit For
End If
Next i
If Not Found Then
MsgBox "Not in list, Please try again"
Combo1 = ""
Combo1.SetFocus
End If
End Sub


hope this helps

Jn88
 
eheheh jn88, you coded + or - what I suggested :) (I'm too exhausted to code) Stevie B. Gibson
 
Got it guys....I didn't use exacty what you guys said because i'm using a DataCombo, which is used with database processing, which has different properites then a normal combo. Just in case you were wondering this is what I came up with:

If cmbEquipNum.BoundText <> &quot;&quot; And Not IsNull(cmbEquipNum) Then
adoEquipNum.Recordset.Find (&quot;DeptNum = &quot; & cmbEquipNum.BoundText)
If adoEquipNum.Recordset.EOF Then
MsgBox &quot;Invalid DeptNum&quot;
End If
End If


Thanks again. :)
Tim
 
Timinator correct me if I'm wrong but you want to use a limit to list property in a combo box right?
So why do you need to code it? You can set the Style property of your combo box to dropdown list(2) and you'll only be able to pick values from the list. Something like Limit to List property on MS Access.
 
daimaou,
Yeah, the dropdown list would limit the selection to whats in the list, but I want the user to be able to type the whole value in if needs be.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top