Can anyone Please help me . How can I in Runtime add
new item in combobox and have it permanently added
to the Combobox List??? When I add on the top it is removed when program stops. Thank you in advance.
Printable View
Can anyone Please help me . How can I in Runtime add
new item in combobox and have it permanently added
to the Combobox List??? When I add on the top it is removed when program stops. Thank you in advance.
how about adding your items from a textfile into your combobox and before the program is closed, storing then back into you file
I can send you an example by email
Here is an example, add a ComboBox called Combo1 and a CommandButton called Command1.
Code:Option Explicit
Private Sub Command1_Click()
AddComboBoxItem Combo1, "Item" & Val(Rnd * 100)
End Sub
Private Sub AddComboBoxItem(cbo As ComboBox, ByVal sItem As String)
Dim iFileNummer As Integer
Dim sCurrentitem As String
'open file
iFileNummer = FreeFile
Open App.Path & "\" & App.ProductName & "_" & cbo.Name & ".dat" For Append As iFileNummer
'Add item
Print #iFileNummer, sItem
'Close file
Close #iFileNummer
'Remeber what item we have currently selected
sCurrentitem = cbo.Text
'Re-read the values
ReadComboBox cbo
'Set item back to the one we had selected
On Error Resume Next
cbo.Text = sCurrentitem
End Sub
Private Sub ReadComboBox(cbo As ComboBox)
Dim iFileNummer As Integer
Dim sItem As String
'Clear ComboBox
cbo.Clear
'Open File
iFileNummer = FreeFile
Open App.Path & "\" & App.ProductName & "_" & cbo.Name & ".dat" For Input As iFileNummer
'Read items
Do Until EOF(iFileNummer)
Line Input #iFileNummer, sItem
'Add item to combobox
cbo.AddItem sItem
Loop
'Close File
Close iFileNummer
End Sub
Private Sub Form_Load()
ReadComboBox Combo1
End Sub
If you are willing to add a command button to your form, as has been suggested, all you need to do is this:
Code:Private Sub Command1_Click()
Combo1.AddItem Combo1.Text
End Sub
Erm in his original post he posted this:Quote:
Originally posted by MartinLiss
If you are willing to add a command button to your form, as has been suggested, all you need to do is this[...]
[/code]
have it permanently added
to the Combobox List??? When I add on the top it is removed when program stops.
I stand corrected. I am so used to storing thing in databases that I overlooked the importance of "when program stops".