RE: identifying, copying, and renaming the newest CSV file for imp



Works like a charm! Thanks a million. Western civilization is saved!

Klatuu wrote:
>I think your idea of looking for the most recent is good provided you are
>confident you will alway get the correct file. So, here is how to use the
>FileSearh object to do what you want:
>
>Sub GetLatestFile
>Dim fs as Object
>Dim lngFileCount as Long
>Dim dtmHighTime As Date
>Dim strHighName As Sting
>Dim strCurrFile As String
>Dim strPath as String
>Dim strOldFile as String
>
>'Set up the search
> set fs = application.FileSearch
> With fs
> .newsearch
> .lookin = "C:\PathToFilesYouWant"
> .filename = "*.csv"
> .searchsubfolders = false
> .execute
>'Look for the Newest file
> For lngFileCount = 1 to .foundfiles.count
> strCurrFile = .foundfiles(lngFileCount)
> If Instr(strCurrFile, "Meth_Full" = 0) Then ' We Dont Want this
>one
> If FileDateTime(strCurrFile) > dtmHighTime Then ' It is Newer
> dtmHighTime = FileDateTime(strCurrFile)
> strHighName = strCurrFile 'Keep track of the most
>recent file
> End If
> End If
> End With
>
> strPath = left(strHighName,instrrev(strHighName,"\")) 'Get the path
> strOldFile = strPath & "DMS_Report.CSV" 'Add the file name
> Kill strOldFile 'Delete the old file
> FileCopy strHighName, strOldFile Copy the new file
>
>End Sub
>
>> The file I want is:
>>
>[quoted text clipped - 28 lines]
>> >>
>> >> Bill

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-externaldata/200511/1
.



Relevant Pages

  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Auto Write Name and Merge across
    ... Dim Sheetname01 As String ... Dim WeekName01 As String ...
    (microsoft.public.excel.misc)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Help answer these 70-310 questions
    ... One argument is the string ... Dim output As New StringBuilder ... EmployeeLocations. ... You create a strongly named serviced component. ...
    (microsoft.public.cert.exam.mcsd)