Check date of file

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

Is there a way to check the date a file was created in
VBA? I have a procedure that automatically creates a
database in a network folder, but sometimes I have lost
the connection to that folder and do not get an error to
trap for. I thought I'd check the date after the file is
created and then have it send me an e-mail if it was not
just created.

Thanks. Rick
 
The date it was created, or the date it was last modified?

Date last modified is easy: VBA has a built-in function FileDateTime that
will give you that.

Date created is a little bit more involved. FSO (FileScriptingObject) can
give it to you:

Dim objFSO As Object, objFile As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = fso.GetFile("c:\detlog.txt")
Debug.Print "File created: " & objFile.DateCreated

You can learn more about FSO at

http://msdn.microsoft.com/library/en-us/script56/html/fsooriScriptingRun-TimeReference.asp

To be honest, though, I don't like using FSO, so I typically use API calls,
such as Randy Birch illustrates at
http://vbnet.mvps.org/code/fileapi/filedatetime.htm

Obligatory warning: Randy's site is aimed at VB programmers. Since there are
significant differences in the controls available for VB forms and those
available for Access forms, some of his examples don't port directly. This
particular one should, though.
 
Back
Top