|
ComboBox - create MRU for dropdown list
'this code tracks the last 10 manual entries into a combolist
'put this in the Keypress event of the combolist
If
KeyAscii
=
13
Then
'this takes effect only when Enter is pressed
'check to see if the entry already exists in the list
'use of LCase make the code case-insensitive
Dim
i
As
Long
, Found
As
Boolean
For
i
=
0
To
cmbList.ListCount
-
1
If
Lcase
$(cmbList.Text)
=
Lcase
$(cmbList.List(i))
Then
Found
=
True
Exit
For
End If
Next
i
'if the text entry is a new item, add it to the top of the list
If
Found
=
False
Then
cmbList.AddItem cmbList.Text, 0
'limit the list to 10 items (drop off bottom item on the list)
If
cmbList.ListCount
>
10
Then
cmbList.RemoveItem (10)
'save the list to a text file if a new item is entered
If
Found
=
True
Then
Open
"searchlist.txt"
For
Output
As
#1
For
i
=
0
To
cmbList.Listcount
-
1
Print
#1, cmbList.list(i)
Next
i
Close
#1
End If
End If
|