ghudson
Registered User.
- Local time
- Yesterday, 19:36
- Joined
- Jun 8, 2002
- Messages
- 6,193
I have inherited an old Access 2 database that I have converted to Access 97. Everything was working great until we just upgraded from Windows 98 to XP. The below date function is returning the wrong date. It keeps returning 11/30/1979 for all files. It is using an old custom function to read a list of files in a directory and the below function is supposed to return the date each file was created. I am hoping that you can spot where the code needs to be tweaked for I have to use this function to avoid a major rewrite of the db.
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 "KERNEL32.dll" Alias "OpenFile" (ByVal szFileName As String, OpenBuff As OFSTRUCT, ByVal flag As Integer) As Integer
Public Function GetFileDateTime(ByVal FileName As String) As Variant
On Error GoTo GetFileDateTime_Err
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)
Rem MsgBox GetFileDateTime
Else
GetFileDateTime = Null
End If
GetFileDateTime_Exit:
Exit Function
GetFileDateTime_Err:
MsgBox Err.Number & " " & Err.Description
Resume GetFileDateTime_Exit
End Function
I have tried padding the date and months but only made things worse.
Thanks in advance for your help!
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 "KERNEL32.dll" Alias "OpenFile" (ByVal szFileName As String, OpenBuff As OFSTRUCT, ByVal flag As Integer) As Integer
Public Function GetFileDateTime(ByVal FileName As String) As Variant
On Error GoTo GetFileDateTime_Err
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)
Rem MsgBox GetFileDateTime
Else
GetFileDateTime = Null
End If
GetFileDateTime_Exit:
Exit Function
GetFileDateTime_Err:
MsgBox Err.Number & " " & Err.Description
Resume GetFileDateTime_Exit
End Function
I have tried padding the date and months but only made things worse.
Thanks in advance for your help!