How to determine mdb file creation date.

Posted on 2006-05-13
Last Modified: 2011-09-20
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.
Question by:Milewskp
    LVL 65

    Expert Comment

    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")
                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
            GetFileCreatedDate = "File Not Found"
        End If
    End function

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

    msgbox sDate

    LVL 65

    Expert Comment

    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
    LVL 77

    Accepted Solution

    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

    LVL 1

    Author Comment

    I'll go with the simpler one. Thanks to you both.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Title # Comments Views Activity
    Help in Creating Access Webapp 7 37
    How get a scanned image on a report 4 15
    Order by 8 19
    Excel To Access Database Transfer 14 23
    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    This isn't a frequent question on EE. I must have seen it three or four times (among several thousand questions). However, I use this trick quite often, most frequently as a delayed Current event. A form does not expose it's calculation dependenc…
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now