Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

How to determine mdb file creation date.

How can I determine the creation date of the current database using code? I believe there is a DAO DateCreated property, but I'm not sure how to use it.
0
Milewskp
Asked:
Milewskp
  • 2
1 Solution
 
rockiroadsCommented:
bit of VBA, add this code into a new module


Option Compare Database

Public Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
    (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FileTimeToSystemTime Lib "kernel32" _
    (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Declare Function FileTimeToLocalFileTime Lib "kernel32" _
    (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long

Public Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type

Public 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 Long
End Type

Public Type WIN32_FIND_DATA
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved0 As Long
    dwReserved1 As Long
    cFileName As String * 260
    cAlternate As String * 14
End Type

Private Function FileDate(FT As FILETIME) As String
'   convert the FILETIME to LOCALTIME, then to SYSTEMTIME type
    Dim ST As SYSTEMTIME
    Dim LT As FILETIME
    Dim t As Long
    Dim ds As Double
    Dim ts As Double
    t = FileTimeToLocalFileTime(FT, LT)
    t = FileTimeToSystemTime(LT, ST)
    If t Then
        ds = DateSerial(ST.wYear, ST.wMonth, ST.wDay)
        ts = TimeSerial(ST.wHour, ST.wMinute, ST.wSecond)
        ds = ds + ts
        If ds > 0 Then
            FileDate = Format$(ds, "mm/dd/yy hh:mm:ss")
        Else
            FileDate = "(no date)"
        End If
    End If
End Function

public function GetFileCreatedDate(byval sFile as String)

'   This subroutine demonstrates the technique
    Dim hFile As Long
    Dim WFD As WIN32_FIND_DATA
    Dim Created As String
    Dim LastWrite As String
     
    hFile = FindFirstFile(sFile, WFD)
   
    If hFile > 0 Then
        Created = FileDate(WFD.ftCreationTime)
        GetFileCreatedDate = Created
    Else
        GetFileCreatedDate = "File Not Found"
    End If
End function



Now simply call   GetFileCreatedDate  passing in the full path of a file, function returns date
e.g.
sDate = GetFileCreatedDate ("C:\MyDB\MyFile.mdb")

msgbox sDate


0
 
rockiroadsCommented:
I think the DateCreated property refers to more a table or some other object in Access.

e.g.  CurrentDb.TableDefs("table1").DateCreated

where table1 is my table

The VBA code I gave u is supposed to work for any file, not just .mdb
You may need to reformat the date to however u want, when u get the return value of GetFileCreatedDate
0
 
peter57rCommented:
Hi Milewskp,
Set a reference to MS Scripting Runtime, then use this:

Sub gefc()
Dim fso As Scripting.FileSystemObject
Dim fil As Scripting.File

Set fso = New Scripting.FileSystemObject
Set fil = fso.GetFile(CurrentDb.Name)

Debug.Print fil.DateCreated, fil.DateLastAccessed, fil.DateLastModified

Set fil = Nothing
Set fso = Nothing
End Sub


Pete
0
 
MilewskpAuthor Commented:
I'll go with the simpler one. Thanks to you both.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now