Results 1 to 9 of 9
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Selecting all listbox choices (2000)

    Hi all,

    The code below searches and returns to a listbox all the text files in a certain directory. The listbox multiselect property is on. How do I make the code automatically select every entry in the listbox?

    <pre>Sub AutoImpFiles()
    'Display a list of files in C:Accounting v4.01ServerIncomingSales
    Set fs = Application.FileSearch
    Set oFN = CreateObject("Scripting.FileSystemObject")
    With fs
    .LookIn = "C:Accounting 4.01ServerIncomingSales"
    .Filename = "*.txt"
    If .Execute > 0 Then
    For i = 1 To .FoundFiles.Count
    PreImport.ListBox1.AddItem oFN.GetFileName(.FoundFiles(i))
    Next i
    <font color=red>'Select all selections in the listbox automatically here</font color=red>
    PreImport.Label1.Caption = .FoundFiles.Count & " files found"
    PreImport.Show
    Else
    MsgBox "There were no files found."
    End If
    End With
    End Sub
    </pre>


  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selecting all listbox choices (2000)

    Have you tried adding

    .Selected(i) = True

    to your loop?

    HTH
    Gre

  3. #3
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selecting all listbox choices (2000)

    I tried that before I made the post, it doesn't seem to work. Thanks anyway.

  4. #4
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selecting all listbox choices (2000)

    I couldn't figure it out, so I think I am going to change it so the action is taken on the choices selected as opposed to the ones which are not selected.

  5. #5
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Selecting all listbox choices (2000)

    Michael,

    Try <pre> For i = 1 To .FoundFiles.Count
    PreImport.ListBox1.AddItem oFN.GetFileName(.FoundFiles(i))
    PreImport.ListBox1.Selected(i - 1) = True
    Next i</pre>

    The ListBox.Selected index starts at zero, so when the first entry is created it should be referred to as 0 and not 1.

    Hope that is of help

    Andrew

  6. #6
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selecting all listbox choices (2000)

    Andrew

    This seems only to select the final item!
    Gre

  7. #7
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Selecting all listbox choices (2000)

    It should select all if the MultiSelect property of the listbox is set to fmMultiSelectMulti or fmMultiSelectExtended it should work. Which is used depends on the designers goals. I have tried it and it works for me.

    Andrew

  8. #8
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selecting all listbox choices (2000)

    <img src=/S/grovel.gif border=0 alt=grovel width=31 height=23> Forgot the box property!
    Gre

  9. #9
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selecting all listbox choices (2000)

    Beautiful! Thanks Andrew!

Posting Permissions

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