Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Sep 2001
    Stuck at work..., Missouri, USA
    Thanked 0 Times in 0 Posts

    Processing order of importing files (2003)

    I have the following code that gets a list of files to import. <pre>FName = Dir(importPath & "PO*.csv")
    Do While FName <> ""
    ImportData = True
    FileList(i) = FName
    'move to the next file in the list
    FName = Dir
    i = i + 1
    TotFiles = i</pre>

    Then that array is run through and the files are imported into my database.

    Is it possible to control the order they are loaded to the array? I NEED to process the oldest file first.

    <font face="Comic Sans MS">Morgan Erickson</font face=comic>
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>-From <img src=/S/flags/Colorado.gif border=0 alt=Colorado width=30 height=18> but living in <img src=/S/flags/Missouri.gif border=0 alt=Missouri width=30 height=18>...and working in Kansas.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Processing order of importing files (2003)

    Dir always loops through the files in alphabetic order. You cannot change that. You could use Application.FileSearch instead. It results in an array of filenames, so you don't have to create the array yourself. And you can also get the number of found files

    Dim i As Integer
    With Application.FileSearch
    .LookIn = importPath
    .Filename = "PO*.csv"
    If .Execute(msoSortByLastModified, msoSortOrderAscending) > 0 Then
    TotFiles = .FoundFiles.Count
    For i = 1 To TotFiles
    Debug.Print .FoundFiles(i)
    Next i
    End If
    End With

    Note: the FoundFiles array contains the complete file names including the path, not just the file names.

    Warning: FileSearch is not available in Office 2007 any more.

Posting Permissions

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