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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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!




  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.

The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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?

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]


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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:

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.