Hi All,
I'm trying to get the TimeStamp of Files I'm importing into my Table tblFileNames...In the table I have the path and File name in the third column I want to know the Time Stamp of each file. I tried the below function, but I keep getting an error message...I would appreciate your help -
Private Sub Form_MyTimeLoad()
Dim db As Database
Dim rst As Variant
Dim NewFile As Variant
DoCmd.Hourglass True
DoCmd.SetWarnings False
Set db = CurrentDb
Set rst = db.TableDefs("TblFileNames").OpenRecordset(dbOpenTable)
rst.MoveFirst
Do Until rst.EOF
NewFile = SaveFileDetails(rst("ImportPath"), rst("ImportName"))
rst.Edit
rst("RunTime") = FileDateTime(rst("ImportPath") & rst("ImportName"))
rst.Update
rst.MoveNext
Loop
DoCmd.Hourglass False
DoCmd.SetWarnings True
End Sub
Function SaveFileDetails(strFilePath As Variant, strFileName As Variant)
'Pass the path to the file, as well as the
'file name, to this function
Dim strFileDate As String
Dim strSQL As String
If strFileName = "" Then
Exit Function
End If
'Get the file date and time
strFileDate = FileDateTime(strFilePath & strFileName)
'Format the date as required for your table
strFileDate = Format$(strFileDate, "dd/mm/yyyy")
strSQL = "INSERT INTO tblFileNames.[Run Time]"
strSQL = strSQL & " VALUES ('" & strFileName & "', '"
strSQL = strSQL & strFileDate & "')"
DoCmd.SetWarnings (False)
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings (True)
End Function
I'm trying to get the TimeStamp of Files I'm importing into my Table tblFileNames...In the table I have the path and File name in the third column I want to know the Time Stamp of each file. I tried the below function, but I keep getting an error message...I would appreciate your help -
Private Sub Form_MyTimeLoad()
Dim db As Database
Dim rst As Variant
Dim NewFile As Variant
DoCmd.Hourglass True
DoCmd.SetWarnings False
Set db = CurrentDb
Set rst = db.TableDefs("TblFileNames").OpenRecordset(dbOpenTable)
rst.MoveFirst
Do Until rst.EOF
NewFile = SaveFileDetails(rst("ImportPath"), rst("ImportName"))
rst.Edit
rst("RunTime") = FileDateTime(rst("ImportPath") & rst("ImportName"))
rst.Update
rst.MoveNext
Loop
DoCmd.Hourglass False
DoCmd.SetWarnings True
End Sub
Function SaveFileDetails(strFilePath As Variant, strFileName As Variant)
'Pass the path to the file, as well as the
'file name, to this function
Dim strFileDate As String
Dim strSQL As String
If strFileName = "" Then
Exit Function
End If
'Get the file date and time
strFileDate = FileDateTime(strFilePath & strFileName)
'Format the date as required for your table
strFileDate = Format$(strFileDate, "dd/mm/yyyy")
strSQL = "INSERT INTO tblFileNames.[Run Time]"
strSQL = strSQL & " VALUES ('" & strFileName & "', '"
strSQL = strSQL & strFileDate & "')"
DoCmd.SetWarnings (False)
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings (True)
End Function