PDA

View Full Version : Solved: Combo Box to list file directory and then remove it



rhxiong
05-08-2007, 01:55 PM
I used this code from JimmyTheHand to list the files in a directory in my combo box.

VBA:

Sub FileList_to_ComboBox(Fldr As String)
Dim sTemp As String

sTemp = Dir(Fldr & "*.*", vbNormal)
Do
If sTemp <> "." And sTemp <> ".." Then
Forms("Form1").Controls("ComboBox1").AddItem sTemp
End If
sTemp = Dir()
Loop Until sTemp = ""
End Sub

---
Now I need to make it so that once I select the item from the combo box, it doesn't show up anymore. I use this box multiple times and if the same files I had selected shows up in the combo box again, I may select the same ones again.

Help??

geekgirlau
05-08-2007, 06:38 PM
I'm not sure exactly what you mean by "using" it, but I think the concept will be that when you select an item in the combo box and perform whatever action is occuring, that item then gets removed (and maybe added to a list box showing actioned items).

When you perform your action on the selected item from your combo box, use ".RemoveItem" to delete it from the list.

rhxiong
05-09-2007, 08:57 AM
Here is an explanation:

I am populating my combo box with the files in a folder as the list. I then select the files using the list from the combo box to import them to different tables. Once I have imported them I want to move and/or remove those files from the original folder so that they will not populate my combo box again.

Any thoughts???

JimmyTheHand
05-09-2007, 10:23 PM
Hi again :hi:

One possible solution is to create a loop that checks all files in the combobox list, whether they exist in the given folder, and if not, then they are removed from the list.
See the code below.

Sub RemoveFiles_from_ComboBox(Fldr As String)
Dim i As Long
With Forms("Form1").Controls("ComboBox1")
For i = .ListCount - 1 To 0 Step -1
If Dir(Fldr & .Column(0, i), vbNormal) = "" Then .RemoveItem (i)
Next
End With
End Sub
Jimmy