by thasnake (2 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)
A simple procedure you can use it works like the Internet Explorer Address Bar. It will save what is typed into the Combo Box and it does not allow duplicate entries to be entered. Please vote if you like it. Sendmessage API can be used also for speed. This is a little simpler because there no declarations.
Private Sub ComboSave(cboName As ComboBox)
On Error GoTo Err:
Dim val As String
Dim i As Long
Dim match As Boolean
val = Trim(cboName.Text)
For i = 0 To cboName.ListCount - 1
If cboName.List(i) = val Then
match = True
Exit For
Else
match = False
End If
Next i
If match = False Then
cboName.AddItem val
'You could add code here to save the values
'to a file or registry or something like that
'so they can be loaded back in next time
'program is started
End If
Exit Sub
Err:
MsgBox "Sorry, there was an error!. " & vbCrLf & _
"Please try again.", vbExclamation, "Error"
End Sub