Need help with FileDateTime in 2002

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

FileDateTime is not working with 2002 and 2003. Looks like
a sand box mode problem. I have Jet Engine 4 service pack 8
installed and still no go.
I placed in a control on my form =FileDateTime("d:\FileName.txt")
Just says error.

Any solutions with this? Any hope of getting it to work?
 
Hi Jay,

It looks like you are correct about this being a sandbox issue. I was able
to get a correct file timestamp returned with Sandbox settings of 0 and 2,
but not with 1 and 3:

0 ---> Sandbox mode is disabled at all times
1 ---> Sandbox mode is used for Access applications,
but not for non-Access Applications
2 ---> Sandbox mode is used for non-Access applications,
but not for Access Applications (Default)
3 ---> Sandbox mode is used at all times

Reference: http://support.microsoft.com/?id=294698

If you want to use a setting of 0 or 3, you can use what is known as a
wrapper function. Create the following function in a new module:

Function GetFileDateTime()
GetFileDateTime = FileDateTime("d:\FileName.txt")
End Function

Set the control source for your text box as follows:

=GetFileDateTime()

Since your example is hard-coded, you might actually want to use a more
flexible function. If the form's recordset includes a field named "FileName",
which specifys the complete path (path + filename.txt), then you can pass
this as a parameter to the function. In this case, change the function to
this:

Function GetFileDateTime(FileName As String) As String
On Error GoTo ProcError

GetFileDateTime = FileDateTime(FileName)

ExitProc:
Exit Function
ProcError:
Select Case Err.Number
Case 53 'File not found
GetFileDateTime = "File not found"
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure GetFileDateTime..."
End Select
Resume ExitProc
End Function


and change the control source to:

=GetFileDateTime([FileName])


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
On second thought, for the more flexible solution I offered, pass the
parameter in as a variant and test for null first. This way, you will avoid a
#Error error on a record that includes no entry in the FileName field, or on
a new record:

Function GetFileDateTime(FileName As Variant) As String
On Error GoTo ProcError

If Not IsNull(FileName) Then
GetFileDateTime = FileDateTime(FileName)
End If

ExitProc:
Exit Function
ProcError:
Select Case Err.Number
Case 53 'File not found
GetFileDateTime = "File not found"
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure GetFileDateTime..."
End Select
Resume ExitProc
End Function


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
 
Tom Wickerath said:
Hi Jay,

It looks like you are correct about this being a sandbox issue. I was able
to get a correct file timestamp returned with Sandbox settings of 0 and 2,
but not with 1 and 3:

0 ---> Sandbox mode is disabled at all times
1 ---> Sandbox mode is used for Access applications,
but not for non-Access Applications
2 ---> Sandbox mode is used for non-Access applications,
but not for Access Applications (Default)
3 ---> Sandbox mode is used at all times

Reference: http://support.microsoft.com/?id=294698

If you want to use a setting of 0 or 3, you can use what is known as a
wrapper function. Create the following function in a new module:

Function GetFileDateTime()
GetFileDateTime = FileDateTime("d:\FileName.txt")
End Function

Set the control source for your text box as follows:

=GetFileDateTime()

Since your example is hard-coded, you might actually want to use a more
flexible function. If the form's recordset includes a field named
"FileName", which specifys the complete path (path + filename.txt), then
you can pass this as a parameter to the function. In this case, change the
function to this:

Function GetFileDateTime(FileName As String) As String
On Error GoTo ProcError

GetFileDateTime = FileDateTime(FileName)

ExitProc:
Exit Function
ProcError:
Select Case Err.Number
Case 53 'File not found
GetFileDateTime = "File not found"
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure GetFileDateTime..."
End Select
Resume ExitProc
End Function


and change the control source to:

=GetFileDateTime([FileName])


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

Jay said:
FileDateTime is not working with 2002 and 2003. Looks like
a sand box mode problem. I have Jet Engine 4 service pack 8
installed and still no go.
I placed in a control on my form =FileDateTime("d:\FileName.txt")
Just says error.

Any solutions with this? Any hope of getting it to work?

Ok I got it. I will work with it. Looks like a simple work around.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top