ACC2: Sample Function to Retrieve File's Date and Time Stamp

Last reviewed: June 8, 1997
Article ID: Q124392
The information in this article applies to:
  • Microsoft Access version 2.0

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article demonstrates a sample user-defined Access Basic function called GetFileDateTime() that you can use to retrieve a file's date and time stamp.

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Access Basic, please refer to the "Building Applications" manual.

MORE INFORMATION

The following example demonstrates how to create and use the GetFileDateTime() function.

NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

  1. Create a new module and enter the following lines in the Declarations section:

          Option Explicit
    

          Type OFSTRUCT
    
             cBytes As String * 1
             fFixedDisk As String * 1
             nErrCode As Integer
             szReserved As String * 4
             szPath As String * 128
          End Type
    
          Global Const OF_EXIST = &H4000
    
          Declare Function WinOpenFile Lib "KERNEL.EXE" Alias _
          "OpenFile" (ByVal szFileName As String, _
          OpenBuff As OFSTRUCT, ByVal Flag As Integer) As Integer
    
    

  2. Enter the following code in the module:

          Function GetFileDateTime (ByVal FileName As String) As Variant
    
             Dim ofs As OFSTRUCT
             Dim iDate As Long
             Dim iTime As Long
    
             Const DAY_MASK = &H1F
             Const MONTH_MASK = &H1E0
             Const YEAR_MASK = &HFE00
    
             Const SECOND_MASK = &H1F
             Const MINUTE_MASK = &H7E0
             Const HOUR_MASK = &HF800
    
             If WinOpenFile(FileName, ofs, OF_EXIST) <> -1 Then
                iDate = Asc(Mid$(ofs.szReserved, 2, 1)) * 256& _
                + Asc(Mid$(ofs.szReserved, 1, 1))
                iTime = Asc(Mid$(ofs.szReserved, 4, 1)) * 256& _
                + Asc(Mid$(ofs.szReserved, 3, 1))
                GetFileDateTime = DateSerial(((iDate And YEAR_MASK) \ _
                &H200) + 1980, (iDate And MONTH_MASK) \ &H20, (iDate And _
                DAY_MASK)) + TimeSerial((iTime And HOUR_MASK) \ &H800, _
                (iTime And MINUTE_MASK) \ &H20, (iTime And SECOND_MASK) * 2)
             Else
                GetFileDateTime = Null
             End If
          End Function
    
    

  3. From the View menu, choose Immediate Window.

  4. Type the following line in the Immediate window, and then press ENTER:

          ?GetFileDateTime("c:\autoexec.bat")
    

    The date and time stamp of the AUTOEXEC.BAT file is returned in the Immediate window.


Additional query words: api return
Keywords : kbprg PgmApi
Version : 2.0
Platform : WINDOWS
Hardware : X86
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.