|
|
Title | Update ComboBox choices when the user enters a new choice |
Keywords | ComboBox, update ComboBox, update choices |
Categories | Controls |
|
|
When the user indicates the entry is finished, search the ComboBox's list of items. If the item is not there, add it.
How the user indicates an entry is finished depends on the program. This example assumes the user is done when focus moves out of the ComboBox.
|
|
' Save any new choice the user entered.
Private Sub cboInterest_LostFocus()
UpdateCombo cboInterest
End Sub
Private Sub UpdateCombo(ByVal cbo As ComboBox)
Dim new_txt As String
Dim i As Integer
Dim found_it As Boolean
' See if the item is in the list.
new_txt = cbo.Text
found_it = False
For i = 0 To cbo.ListCount - 1
If new_txt = cbo.List(i) Then
found_it = True
Exit For
End If
Next i
' If the item is not in the list, add it.
If Not found_it Then
cbo.AddItem new_txt
End If
End Sub
|
|
|
|
|
|