Consulting

Results 1 to 4 of 4

Thread: Solved: Combo Box to list file directory and then remove it

  1. #1
    VBAX Newbie
    Joined
    May 2007
    Posts
    5
    Location

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

    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??

  2. #2
    VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    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.

  3. #3
    VBAX Newbie
    Joined
    May 2007
    Posts
    5
    Location
    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???

  4. #4
    Hi again

    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.

    [vba]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[/vba]
    Jimmy
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •