Milewskp
asked on
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.
I think the DateCreated property refers to more a table or some other object in Access.
e.g. CurrentDb.TableDefs("table 1").DateCr eated
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
e.g. CurrentDb.TableDefs("table
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'll go with the simpler one. Thanks to you both.
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
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.ftCreationTim
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