Help please: Getting file create date in Access 
Author Message
 Help please: Getting file create date in Access

I've created an access db to track files and info about them. I'm
using the built-in function FileDateTime() to get the file's modified
date, but I also need to get the create date and as far as I can tell
access doesn't provide a function to get it.

Is there a VBA wrapper for an API call I can use to get this info? Any
help or sample code would be appreciated.

Thanks in advance,
ben




Sun, 14 Oct 2001 03:00:00 GMT  
 Help please: Getting file create date in Access
Hi Ben,

This turned out to be quite interesting actually. :-)

Can anyone tell us why the times seem to be offset a bit when compared to
Explorer/Info on the file?

'******* Code Star t********
Private Type FILETIME
   dwLowDateTime As Long
   dwHighDateTime As Long
End Type

Private Type SYSTEMTIME
   wYear As Integer
   wMonth As Integer
   wDayOfWeek As Integer
   wDay As Integer
   wHour As Integer
   wMinute As Integer
   wSecond As Integer
   wMilliseconds As Integer
End Type

Private Declare Function apiCreateFile Lib "kernel32" _
   Alias "CreateFileA" _
   (ByVal lpFileName As String, _
   ByVal dwDesiredAccess As Long, _
   ByVal dwShareMode As Long, _
   ByVal lpSecurityAttributes As Long, _
   ByVal dwCreationDisposition As Long, _
   ByVal dwFlagsAndAttributes As Long, _
   ByVal hTemplateFile As Long) _
   As Long

Private Declare Function apiCloseHandle Lib "kernel32.dll" _
  Alias "CloseHandle" _
  (ByVal hObject As Long) _
  As Long

'retrieves the date and time that a file was created,
'last accessed, and last modified.
Private Declare Function apiGetFileTime Lib "kernel32" _
   Alias "GetFileTime" _
   (ByVal hFile As Long, _
   lpCreationTime As FILETIME, _
   lpLastAccessTime As FILETIME, _
   lpLastWriteTime As FILETIME) _
   As Long

'converts a 64-bit file time to system time format.
Private Declare Function apiFileTimeToSystemTime Lib "kernel32" _
   Alias "FileTimeToSystemTime" _
   (lpFileTime As FILETIME, _
   lpSystemTime As SYSTEMTIME) _
   As Long

Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const CREATE_ALWAYS = 2
Private Const INVALID_HANDLE_VALUE = -1
Private Const FILE_SHARE_READ = &H1
Private Const FILE_ATTRIBUTE_NORMAL = &H80

Public Function fGetFileTime(strFileName As String, _
                                       intTimeType As Integer) _
                                       As String
'strFileName:     Full path to the file
'intTimeType:     = 1 to retrieve Creation Time
'                      =  2 To retrieve Last Access Time
'                      = 3 to retrieve LastWrite Time
On Error GoTo ErrHandler
Dim lngRet As Long
Dim lpCreation As FILETIME
Dim lpLastAccess As FILETIME
Dim lpLastWrite As FILETIME
Dim lpSystem As SYSTEMTIME
Dim hFile As Long
Const conERR_GENERIC = vbObjectError + 5000

   If Len(Dir(strFileName)) = 0 Then _
         Err.Raise conERR_GENERIC

   hFile = apiCreateFile(strFileName, GENERIC_READ, _
               FILE_SHARE_READ, 0&, OPEN_EXISTING, _
               FILE_ATTRIBUTE_NORMAL, 0)

   If hFile = INVALID_HANDLE_VALUE Then _
         Err.Raise conERR_GENERIC

   lngRet = apiGetFileTime(hFile, lpCreation, lpLastAccess, lpLastWrite)

   If lngRet = 0 Then Err.Raise conERR_GENERIC

   Select Case intTimeType
      Case 1:     'Creation Time
         lngRet = apiFileTimeToSystemTime(lpCreation, lpSystem)
      Case 2:     'LastAccess Time
         lngRet = apiFileTimeToSystemTime(lpLastAccess, lpSystem)
      Case 3:     'LastWrite time
         lngRet = apiFileTimeToSystemTime(lpLastWrite, lpSystem)
      Case Else:  'invalid value
         Err.Raise conERR_GENERIC
   End Select

   If Not lngRet = 0 Then
      With lpSystem
         fGetFileTime = Format$(.wMonth & "/" & .wDay & "/" & .wYear _
               & " " & .wHour & ":" & .wMinute & ":" & .wSecond, "general
date")
      End With
   End If
ExitHere:
   Call apiCloseHandle(hFile)
   Exit Function
ErrHandler:
   fGetFileTime = vbNullString
   Resume ExitHere
End Function
'******* Code End********

HTH
--
Dev Ashish (Just my $.001)
---------------
The Access Web ( http://home.att.net/~dashish )
---------------


: I've created an access db to track files and info about them. I'm
: using the built-in function FileDateTime() to get the file's modified
: date, but I also need to get the create date and as far as I can tell
: access doesn't provide a function to get it.
:
: Is there a VBA wrapper for an API call I can use to get this info? Any
: help or sample code would be appreciated.
:
: Thanks in advance,
: ben
:



Sun, 14 Oct 2001 03:00:00 GMT  
 Help please: Getting file create date in Access
Hi Chuck,

  Aha! Thanks for the info.  Didn't get that fact from MSDN.

  Just one minor correction, the API needs an alias.

    Declare Function apiGetTimeZoneInformation Lib "kernel32" _
      Alais "GetTimeZoneInformation" _
   (lpTimeZoneInformation As TIME_ZONE_INFORMATION) _
       As Long

    TA
  -- Dev


Quote:
>Sorry it's taken me so long to reply, Dev & Ben.  I've been busy, and
>there hasn't been much of a chance for me to play with the fun
>stuff... <sigh>

>Anyways, the problem here is that GetFileTime returns the time and
>date in GMT (AKA "UTC" or "Universal") time, rather then the local
>system time.  So, you need to convert that.  As might be expected,
>that's another API call.  Merge the below into the module, and it
>should work as expected....  (I'm sure someone will tell me if what's
>below is wrong or not working, but it should.  It's from a working
>project I did a few months ago.)

<snip>


Fri, 19 Oct 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. HELP: File Properties - Create, Modified, Accessed Dates.

2. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

3. Help Please! DataBound Control Accessing Access Date Column

4. Getting Date Access of a DOS file !

5. Need help getting the date from Access

6. Getting File Information (Date/Time/Attrib) Help Needed!

7. Please, Please, Please I need help working with dates

8. *********** Please Help with HOW TO CREATE HELP FILE **************************

9. creating help files with WinWord6 - please help

10. Insert DATE into Access 2000 -- PLEASE HELP!!!

11. MS Access and Dates, please help

12. Please help with getting info from a file

 

 
Powered by phpBB® Forum Software