FileDateTime Question

J

Jay

I have gotten my code this far but not working.



Dim MyStamp as Date

MyStamp = FileDateTime(C:\Filecopy.txt)
If MyStamp = Date Then
'If Filecopy.txt modified date equals the current date.
MsgBox "File ok"
Goto End1
End If
MsgBox "File not ok"
End1:
 
J

Jeff Boyce

Jay

"... not working..." is pretty loose...

Do you mean that it returns a value, but the wrong one?

Do you mean that it sometimes returns a wrong value, and sometimes the right
one?

Do you mean that it fails and generates an error message? (what does the
message say?)

Do you mean that your PC bursts into flames when you try this?

More specific descriptions will lead to more specific suggestions...

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
J

Jay

Jeff said:
Jay

"... not working..." is pretty loose...

Do you mean that it returns a value, but the wrong one?

Do you mean that it sometimes returns a wrong value, and sometimes the
right one?

Do you mean that it fails and generates an error message? (what does the
message say?)

Do you mean that your PC bursts into flames when you try this?

More specific descriptions will lead to more specific suggestions...

Regards

Jeff Boyce
Microsoft Office/Access MVP


Sorry about that. I just got off google and my head is spinning in
circles.

I have a need to compair a text file's modification date with the current
date. If it matches then it is good. If the modification date is older
then it is rejected.

I made a filecopy.txt file with the modified date matching the current date.
However, I get the msgbox "File not ok".

I am not getting a match between the current date and the modified date of
the file.
 
J

Jeff Boyce

Jay

Were this my task, I'd probably start out displaying what the FileDateTime
actually is, before trying to compare.

By the way, if the name implies accurately, the value is a date/time value,
so comparing to only a date won't get it. You might want to take a look at
the functions that extract the date-only portion...

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
D

Douglas J. Steele

I'm surprised you're not getting an error. The argument to FileDateTime
needs to be a string:

MyStamp = FileDateTime("C:\Filecopy.txt")

Note though, that FileDateTime is going to return a date/time combination,
whereas Date only returns the date. The odds of you finding them with the
same value are extremely small (the file would have had to have been updated
at midnight this morning). To strip the time off MyStamp, use the DateValue
function:

If DateValue(MyStamp) = Date Then
 
J

Jay

Douglas said:
I'm surprised you're not getting an error. The argument to FileDateTime
needs to be a string:

MyStamp = FileDateTime("C:\Filecopy.txt")

Note though, that FileDateTime is going to return a date/time combination,
whereas Date only returns the date. The odds of you finding them with the
same value are extremely small (the file would have had to have been
updated at midnight this morning). To strip the time off MyStamp, use the
DateValue function:

If DateValue(MyStamp) = Date Then


That worked.
I had everything but the DateValue which gave me the date only.
 

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

Top