A ComboBox Procedure to save its contents.
![Visual Basic 6, or VB Classic Visual Basic 6, or VB Classic](https://www.fortypoundhead.com//assets/img/icons/v7/vb6.png)
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.
Original Author: thasnake
Code
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
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.