Question : Update Query (or VBA) which updates a database with the date of the last file created in a folder

I have the following code that BlueDevilFan wrote.

So this code looks into a folder and finds the most recent file created in that folder. And subtracts that date from todays date.

So I want to use this code o something similar to update a table on the database. So, the query will check each fund in the table and the corresponding folder. It will check the latest file and grab the date. And update a table with the corresponding dates.

So,
The update query will look into Fundinfo!FundName (name of the fund) and FundInfo!Folder(location of the folder like c:\aa\loca). It will check the date of the last file created under (c:\aa\loca). Then, it will go to modhist!FundName (fundname) and modhist!LastFileDate (date of the last file created in a folder) and update the modhist!LastFileDate with the creation date of the most recent file under c:\aa\loca)

I hope this is easy to understand. If you have questions let me know




1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Public Function DateNewestFileInFolder(strFolderPath As String) As Integer
    Dim objFSO As FileSystemObject, objFolder As Object, objFile As File, intTemp As Integer, bolFirstPass As Boolean
    Set objFSO = CreateObject("Scripting.FileSystemobject")
    Set objFolder = objFSO.GetFolder(strFolderPath)
    bolFirstPass = True
    For Each objFile In objFolder.Files
        intTemp = DateDiff("d", objFile.DateCreated, Date)
        If bolFirstPass Then
            NewestFileInFolder = intTemp
            bolFirstPass = False
        Else
            If intTemp < NewestFileInFolder Then NewestFileInFolder = intTemp
            
        End If
    Next
    Set objFile = Nothing
    Set objFolder = Nothing
    Set objFSO = Nothing
End Function

Answer : Update Query (or VBA) which updates a database with the date of the last file created in a folder

Forgive my typos....
1:
2:
3:
4:
5:
Set rs = CurrentDb.OpenRecordset("select fundname, folder from FundInfo", dbOpenSnapshot)

Do While Not rs.EOF
     CurrentDb.Execute ("update modHist set LastFileDate = #'" & DateNewestFileInFolder(rs("folder")) & "'# where fundName = '" & rs("fundname") & "'")
Loop
Random Solutions  
 
programming4us programming4us