Getting the date modified value of a file.

Hi there

I don't know whether Access will provide me with the solution.

Here's the problem ....

I need to develop a program that will check the date mofidfied of a file on the server and compare it to the one that is on my PC. The file names are the same. If the one on the server is more updated than the one on my PC then I have to copy the one on the server to my PC.

I know I have to extract the date modified values of both files and do the comparison.

How would I do something like this or would Visual Basic remedy the problem?

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

BrianWrenConnect With a Mentor Commented:
Well, I was actually giving what is called a 'code snippet.'  The idea was to put it into a procedure, as follows.

On a form, put a command button, name it 'btnFileUpdate', and set its Click property to [Event Procedure].  Then click the elipsis to the right of the Click property, (the [...] button).

You will see

Private Sub btnFileUpdate()

End Sub

(You will need to change the file names I use below to reflect the true names and locations of your situation.)

Edit the sub so that it looks like:

Private Sub btnFileUpdate()

   On Error GoTo F_Ud_Err

   ' Next 2 lines is where you put your specific case.
   Const FileLoc = "C:\FileLoc\DataFile.txt"
   Const FileSvr = "\\Svr015\FileLoc\DataFile.txt"

   Dim fTimeLoc As Variant
   Dim fTimeSvr As Variant
   fTimeLoc = FileDateTime(FileLoc)
   fTimeSvr = FileDateTime(FileSvr)

   If fTimeSvr < fTimeLoc Then
      FileCopy FileLoc, FileSvr
      MsgBox "File was transferred"
      MsgBox "File was not transferred"
   End If

   Exit Sub

   MsgBox Err.Number & ", " & Err.Description
   Resume F_Ud_Res

End Sub

Save the form, run it, and when you click the button, the file dates and times will be retrieved, and if the server version is older, the server version will be replaced by the local version, and a message box will be displayed to let you know which action was taken.

If an error is encountered, you will be notified of that instead, and the sub will gracefully close.

That's a lot of answer for 27 points...  :o]


You can do this in access code with the following API:

        dwLowDateTime As Long
        dwHighDateTime As Long
End Type

Declare Function GetFileTime Lib "kernel32" Alias "GetFileTime" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long

...or to be simpler, check out


LAPAuthor Commented:

Firstly, I don't have Visual FoxPro on my PC so I assume I can't make use of the code.

I've looked at the code at the site. It's seems quite complex and lengthy.

Doesn't MS Access have a simpler function!

The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.




  Dim MyStamp As Variant

  ' Assume TESTFILE was last modified on Feb. 12, 1993 at 4:35:47 PM.
  ' Assume English/U.S. locale settings.
  MyStamp = FileDateTime("TESTFILE")      ' Returns "2/12/93 4:35:47 PM".

You can call this function to fill in one variant with one call, and a different variant with a second call, (using different strings for the argument to the FileDateTime function), then compare the results.

LAPAuthor Commented:


when I compile that code I get the following error msg "Compile error: Invalid outside procedure"

How do I specify the path where the file can be found?

LAPAuthor Commented:

Unable to make use of the example for  Visual FoxPro.

....sorry  :-(
LAPAuthor Commented:


I am increasing the points to 100. :-)

I'll then accept your comment as the answer.

Thanks .... Leigh
LAPAuthor Commented:

All Courses

From novice to tech pro — start learning today.