Forum Discussion

phurinatpanson's avatar
phurinatpanson
Copper Contributor
Aug 01, 2024

How to append only today's date modified text files to a table in Access?

Hi

 

I have text files added to the folder every day, that folder is the entire database. Each day I want to append only today's date modified text files to a table in Access.

1 Reply

  • Steve_Titus's avatar
    Steve_Titus
    Copper Contributor

    phurinatpanson 

     

    Use the Files collection and File object to get the files you want and the perhaps the DoCmd.TransferText method to import your data.

     

    Steve

     

    Sub ShowFileInfo(filespec)
        Dim fs, f, s
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFile(filespec)
        s = f.DateCreated
        MsgBox s
    End Sub
    

    https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/file-object

     

    Sub ShowFolderList(folderspec)
        Dim fs, f, f1, fc, s
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFolder(folderspec)
        Set fc = f.Files
        For Each f1 in fc
            s = s & f1.name 
            s = s & vbCrLf
        Next
        MsgBox s
    End Sub
    

    https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/files-collection

     

    The with the ShowFolderList you'll have a collection of all the files in your directory and ShowFileInfo should all you to test for the creation date.  Investigate the TransferText method to import into a table

     

    Steve

Resources