Import if timestamp is new

renenger

Registered User.
Local time
Today, 10:17
Joined
Oct 25, 2002
Messages
117
I am creating an Access database that will be importing data from a .csv file several times a day. Every time a user tries to run a report it will run this update to ensure they have the latest information.

Can I create some kind of code that states the table was updated at a certain time with a timestamp and when it runs the code to retrieve the .csv file compare that timestamp to the timestamp on the file? If the timestamp on the file is newer than the timestamp on the last update, then update if not do not update?
 
You can create a single-record table say "tblTimeStamp" with a date/time field "LastUpdate" to record the timestamp of the last csv file.

Then run code similar to the following to compare the csv timestamp with the last update:
Code:
   Dim CSVTimeStamp As Date
   Dim LastUpdate As Date
   
   CSVTimeStamp = FileDateTime("C:\Test.csv")
   LastUpdate = DLookup("LastUpdate", "tblTimeStamp")
   
   If CSVTimeStamp > LastUpdate Then
      ' ..... update ....
      ' .................
      
      CurrentDb.Execute "Update [tblTimeStamp] set [LastUpdate]='" & CSVTimeStamp & "'"
      
      MsgBox "File updated."
   Else
   
      MsgBox "No newer csv file."
   End If
.
 

Users who are viewing this thread

Back
Top Bottom