Use DateDiff & FileDateTime to display age of file as of today.

P

pilch74

I just wanted to say 'hi' first of all, I'm a relative n00b to Access n
the scheme of things and a colleague recommended Google Groups for
advice and hear I am.

Having already subscribed to some groups that suit my particular taste
I would like to share a function that combines the DateDiff and the
FileDateTime functions to display the number of days between an
external file and today's date. Of course this can be tweaked to your
liking.

This example below says 'Check to see if dates.txt is older than 36
days'

DateDiff("d",Date(), FileDateTime("D:\_EXTRACTS_\dates.txt")) >= -36

This will hopefully be of use for anyone who needs to check the age of
an external file prior to using the TransferText command within a macro
to populate a table.

Don't forget that you can do some nice test debugs using the
'Immediate' window panel (CTRL&G) within VBA mode) first to get a feel
for your functions and dates of files etc.. i.e

Debug.Print DateValue(FileDateTime("D:\_EXTRACTS_\dates.txt"))Date()

- will show you the date of dates.txt and today's date.

I hope this makes sense, English was never my strong point.

And also perhaps as a security measure we should all be checking if the
file exists first ?

Regards,

Richard
 

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

Similar Threads


Top