VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A ComboBox Procedure to save its contents.

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.

Rate A ComboBox Procedure to save its contents.

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

Download this snippet    Add to My Saved Code

A ComboBox Procedure to save its contents. Comments

No comments have been posted about A ComboBox Procedure to save its contents.. Why not be the first to post a comment about A ComboBox Procedure to save its contents..

Post your comment

Subject:
Message:
0/1000 characters