Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text File Import Issue

Status
Not open for further replies.

kopy

Technical User
May 30, 2002
141
US
I have to import a text file that has a suffix in the name that changes every time it runs. Here is an example of the file name with the suffix.

DoCmd.TransferText acImportDelim, "", "PHR_HS_OCC_HLT_BBP_DB-1212845.csv", True, ""

I've tried to put a wildcard into the name so that the most current file with any suffix will be imported.

DoCmd.TransferText acImportDelim, "", "PHR_HS_OCC_HLT_BBP_DB" & "*" & ".csv", True, ""

My problem is that the file can not be found and it appears that the wildcard isn't working.

Any help will be appreciated. Thanks, Kopy
 
How about using the FileSystemObject to get the latest version of the file, would that work?
 
Thanks for getting back to me.

I'm not sure how to use the FileSystemObject. Can you show me?

Kopy
 
Code:
'Reference: Microsoft Scripting Runtime
Dim f As File, fl As Folder, fs As FileSystemObject
Dim fd As Date
Dim fname As String

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set fl = fs.GetFolder("C:\Docs")
    
    For Each f In fl.Files
        If IsNull(fd) Or f.DateCreated > fd Then
            fd = f.DateCreated
            fname = f.Name
        End If
    Next
    
    Debug.Print fd, fname

--
 
One word of warning - some email/virus checkers can, by default, block .mdb files that utilise the filesystemobject. I recently used it to great effect but when it came to distributing it to regional offices throughout Australia our software, "Mail Marshal" prevented it from being delivered, even internally within our own company network!

I'm sure there is a way to stop this blockage happening but if you happen to work for a large company where the appropriate department are 4000km away and as useful as mud-flaps on a tortoise this can be rather annoying.

Sorry this is a bit off thread but just wanted to mention it :) JB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top