ACC2: Sample Function to Retrieve File's Date and Time StampID: Q124392
|
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.
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.
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
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
Additional query words: api return
Keywords : kbprg
Version : 2.0
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: April 7, 1999