Finding file info from Access function

G

Guest

I have a button on my form that runs this;
strFileName = "EXTRACT.TXT"
Set fs = Application.FileSearch
With fs
.LookIn = strSourceLocation
.FileName = strFileName
'JES-06/05/07 If there is an existing file then......
If .Execute > 0 Then
' Go somewhere and determine file Create and Modify Dates
Now that I have verified the existence of the file I need to know its'
Create and Modified date. How do I go about this ?
 
D

Douglas J. Steele

Assuming you're only looking in the folder pointed to by strSourceLocation,
a far easier way to verify the existence is:

If Len(Dir(strSourceLocation & strFileName)) > 0 Then
' file exists
Else
' file doesn't exist
End If

(This assumes strSourceLocation ends with a slash)

Modify date is easy: FileDateTime(strSourceLocation & strFileName)

Create date is harder. There's no function built into VBA to give you that:
you need to use either FSO, or an API call.

Randy Birch has a good example of how to use APIs to do this at
http://vbnet.mvps.org/code/fileapi/filedatetime.htm (Obligatory warning:
Randy's site is aimed at VB programmers. There are significant differences
between the controls available for forms in VB and in Access, so some of his
examples won't port directly into Access. Looking at this particular sample,
though, I don't see any problems)

An example of using FSO would be something like:

Dim objFSO As Object
Dim objFile As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strSourceLocation & strFileName) Then
Set objFile = objFSO.GetFile(strSourceLocation & strFileName)
MsgBox strFileName & " was created on " & objFile.DateCreated & _
" and was last modified on " & objFile.DateLastModified
End If

Set objFile = Nothing
Set objFSO = Nothing
 
G

Guest

You should also be aware of some of the limitations of using these dates. For
instance, if you use Windows to look at the last modified date, it changes
the date.

Dorian
 
G

Guest

I was wrong. I only needed the modify date. I chnaged my code to your
recommendation and it works great. Thank you
 
D

Douglas J. Steele

I don't think so. Perhaps you're thinking about LastAccessedDate, rather
than LastModifiedDate.
 

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