Results 1 to 5 of 5
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371

    Adding List Item In Modified Order

    Hi Guy's I am trying add folder contents to a listbox but show last modified at the top of the list ?



    It is coming up .AddItem = Is Not An Option ?

    Dim fPath is set to string

    Code:
       Dim FSO As FileSystemObject    Dim FO As Folder, FI As file, FIs As Files
        Dim FileList()
        Dim I As Long
    
    
    Set FSO = New FileSystemObject
    Set FO = FSO.GetFolder(fPath)
    Set FIs = FO.Files
    
    
    ReDim FileList(1 To FIs.Count, 1 To 2)
    I = 0
    
    
    For Each FI In FIs
        I = I + 1
        FileList(I, 1) = FI.Name
        FileList(I, 2) = FI.DateLastModified
    Next FI
        Me.lstPODS.AddItem = FileList
    
    
    End If

  2. #2
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    My other method adds the files but not in order so i am unsure if using FSO is the best solution or if the following method can be adapted to re arrange file name in date last modified order ?

    Code:
    FileName = Dir(fPath & "\*.pdf", vbNormal)Do While Len(FileName) > 0
    Me.lstPODS.AddItem FileName
    FileName = Dir()
    Loop

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    I believe you need to add one at a time, so put the AddItem inside the loop.?
    Also fpath is not defined?

    You might need to sort the array?
    http://etutorials.org/Microsoft+Prod...+Array+in+VBA/

    or using a collection (which I have never used)

    https://stackoverflow.com/questions/...y-sort-listbox
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,880
    How about something like this?
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    hey thank you Moke 123, i am a little busy but for a short while but so looking forward to studying your method

    Kindest

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 12
    Last Post: 06-08-2021, 09:46 AM
  2. Replies: 3
    Last Post: 08-13-2020, 02:47 PM
  3. Replies: 5
    Last Post: 03-21-2016, 09:46 PM
  4. Replies: 2
    Last Post: 03-07-2016, 05:02 PM
  5. Replies: 2
    Last Post: 04-05-2012, 08:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums