Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-access > #14329

Re: [A2010] MDB creation file

From Ron Weiner <rw@domain.com>
Newsgroups comp.databases.ms-access
Subject Re: [A2010] MDB creation file
Date 2021-07-23 16:19 -0400
Organization WorksRite
Message-ID <sdf89d$5nm$1@dont-email.me> (permalink)
References <XnsAD709F33F387Eammammatatiscalineti@127.0.0.1> <sdejhk$dgh$1@dont-email.me> <XnsAD70AD3AF684Dammammatatiscalineti@127.0.0.1>

Show all headers | View raw


Back in the "olden days", I was responsible for archiving sets of Video 
files where the customer was VERY particular about the Created, Last 
Accessed, and Modified date-times.  It has been quite some time, and I 
do not recall specifically what our issue was, but I wound up having to 
completely take over all of these dates and times from my code.

I wrote a pair of functions that were placed in a separate code module. 
 One function reads the 3 values from a file, and the other writes 
them.

As far as I know that app is still in use today.  The app was written 
in VB6, but should be a direct port to Access.  To use it in Access 
create a new Code Module then copy and paste all of the code from 
below.  Watch for word wrap.  Here's the code.

' -=-=-=-=-=-=-=-=-=-=-=-=-= Code Starts -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Option Explicit

Private Type FILETIME
    LowDateTime As Long
    HighDateTime As Long
End Type

Private Type SYSTEMTIME
    Year As Integer
    Month As Integer
    DayOfWeek As Integer
    Day As Integer
    Hour As Integer
    Minute As Integer
    Second As Integer
    Milliseconds As Integer
End Type

Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const FILE_ATTRIBUTE_ARCHIVE = &H20

Private Declare Function CreateFile 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 CloseHandle Lib "kernel32" (ByVal hObject As 
Long) As Long
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As 
Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, 
lpLastWriteTime As FILETIME) As Long
Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As 
Long, lpCreationTime As Any, lpLastAccessTime As Any, lpLastWriteTime 
As Any) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" 
(lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32.dll" 
(lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" 
(lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" 
(lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function SystemTimeToVariantTime Lib "OLEAUT32" 
(lpSystemTime As SYSTEMTIME, vtime As Date) As Long
Private Declare Function VariantTimeToSystemTime Lib "OLEAUT32" (ByVal 
vtime As Double, ByRef lpSystemTime As SYSTEMTIME) As Long

Public Sub FileSetDates(strFilename As String, dteCreate As Date, 
dteAccessed As Date, dteModified As Date)
' Purpose   Set Date/Time of all three file File Date/Times
'       Pass the fullsilespec to the file you want to set the 
Date/Times
'       Pass the DateTime for each of the 3 File Date/Time values

    Dim hFile As Long, RetVal As Long
    Dim SysTimeCreate As SYSTEMTIME, SysTimeAccessed As SYSTEMTIME, 
SysTimeModified As SYSTEMTIME
    Dim ftCreateTimeLocal As FILETIME, ftAccessedTimeLocal As FILETIME, 
ftModifiedTimeLocal As FILETIME
    Dim ftCreateTime As FILETIME, ftAccessedTime As FILETIME, 
ftModifiedTime As FILETIME

    ' Convert From a VB Date Type to a SYSTEMTIME Type
    RetVal = VariantTimeToSystemTime(CDbl(dteCreate), SysTimeCreate)
    RetVal = VariantTimeToSystemTime(CDbl(dteAccessed), 
SysTimeAccessed)
    RetVal = VariantTimeToSystemTime(CDbl(dteModified), 
SysTimeModified)

    ' Convert SYSTEMTIME to Local FILETIME
    SystemTimeToFileTime SysTimeCreate, ftCreateTimeLocal
    SystemTimeToFileTime SysTimeAccessed, ftAccessedTimeLocal
    SystemTimeToFileTime SysTimeModified, ftModifiedTimeLocal

    ' Convert Local FILETIME to GMT
    LocalFileTimeToFileTime ftCreateTimeLocal, ftCreateTime
    LocalFileTimeToFileTime ftAccessedTimeLocal, ftAccessedTime
    LocalFileTimeToFileTime ftModifiedTimeLocal, ftModifiedTime

    ' Open the file to get the filehandle
    hFile = CreateFile(strFilename, GENERIC_WRITE, FILE_SHARE_READ Or 
FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
    If hFile Then
        ' File opened - Set all of the File Times
        RetVal = SetFileTime(hFile, ftCreateTime, ftAccessedTime, 
ftModifiedTime)
        ' Close file
        RetVal = CloseHandle(hFile)
     Else
        ' Poopies
        MsgBox "CreatFile failed in FileSetDates()"
    End If

End Sub

Public Sub FileGetDates(ByVal strFilename As String, ByRef 
dteCreateTime As Date, _
                        ByRef dteLastAccessTime As Date, ByRef 
dteLastModifiedTime As Date)
' Purpose   Get all of the date and times associated with the filename 
specified
'       Pass the fullsilespec to the file you want to get the 
Date/Times from
'       Sub will place the Create, Last Accessed, and Last Modified 
dates of the file in the Parameters passed by ref

    Dim hFile As Long, RetVal As Long

    Dim cTime As FILETIME       ' DateTime as written on the media
    Dim aTime As FILETIME
    Dim mTime As FILETIME

    Dim cTimeLocal As FILETIME  ' DateTime converted to users time zone
    Dim aTimeLocal As FILETIME
    Dim mTimeLocal As FILETIME

    Dim CreateTime As SYSTEMTIME        ' Used as interim step for 
conversion to a VB Date Type
    Dim LastAccessTime As SYSTEMTIME
    Dim LastModifiedTime As SYSTEMTIME

    ' Open the file
    hFile = CreateFile(strFilename, GENERIC_READ, FILE_SHARE_READ, 
ByVal CLng(0), OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0)
    If hFile Then
        ' Well at least that worked
        ' Get the Dates
        RetVal = GetFileTime(hFile, cTime, aTime, mTime)
        ' Close the file
        RetVal = CloseHandle(hFile)

        ' Convert FILETIME as written on the media to the users Local 
FILETIME (was written as GMT)
        RetVal = FileTimeToLocalFileTime(cTime, cTimeLocal)
        RetVal = FileTimeToLocalFileTime(aTime, aTimeLocal)
        RetVal = FileTimeToLocalFileTime(mTime, mTimeLocal)

        ' Convert Local FILETIME Type to SYSTEMTIME Type
        RetVal = FileTimeToSystemTime(cTimeLocal, CreateTime)
        RetVal = FileTimeToSystemTime(aTimeLocal, LastAccessTime)
        RetVal = FileTimeToSystemTime(mTimeLocal, LastModifiedTime)

        ' Convert SYSTEMTIME to a VB Date type
        RetVal = SystemTimeToVariantTime(CreateTime, dteCreateTime)
        RetVal = SystemTimeToVariantTime(LastAccessTime, 
dteLastAccessTime)
        RetVal = SystemTimeToVariantTime(LastModifiedTime, 
dteLastModifiedTime)
    Else
        ' Poopies
        MsgBox "CreatFile failed in FileGetDates()"
    End If

End Sub

' -=-=-=-=-=-=-=-=-=-=-=-=-= Code Ends -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Back to comp.databases.ms-access | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[A2010] MDB creation file Ammammata <ammammata@tiscalinet.it> - 2021-07-23 13:38 +0000
  Re: [A2010] MDB creation file Neil <neil@myplaceofwork.com> - 2021-07-23 10:16 -0400
    Re: [A2010] MDB creation file Ammammata <ammammata@tiscalinet.it> - 2021-07-23 15:02 +0000
  Re: [A2010] MDB creation file Ron Weiner <rw@domain.com> - 2021-07-23 10:25 -0400
    Re: [A2010] MDB creation file Ammammata <ammammata@tiscalinet.it> - 2021-07-23 15:01 +0000
      Re: [A2010] MDB creation file Ron Weiner <rw@domain.com> - 2021-07-23 16:19 -0400
        Re: [A2010] MDB creation file Ammammata <ammammata@tiscalinet.it> - 2021-07-29 13:53 +0000

csiph-web