Advertisement
7_2009-2012 Custom Controls/ Forms/ Menus #233199

A ComboBox Procedure to save its contents.

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.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
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
Original Comments (3)
Recovered from Wayback Machine