Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding Last Modified Dates for an Access file and an Access table 1

Status
Not open for further replies.

IoMatua

Programmer
Mar 27, 2003
17
NZ
Hi.

I have an Access database that contains certain values which I can extract using VBA in Excel, then I perform calculations on those values and then store the results into an Excel spreadsheet.

What I want to do is to check the .mdb file to see if it was modified since the last time I acessed it from the Excel macro (I'll probably store the Last Accessed date inside an INI file) and if it has been modified, go to the table that contains the values I need, and check to see if that was modified. If it has been modified, redo the calculations and store the new results back into the Excel sheet.

Hopefully the explanation of my problem is sufficient. Any help with this will be greatly appreciated.
Thanks in advance.

 
Hi IoMatua,

I think that the best way to retrieve any file related information / attributes is to use the FileSystemObject (scrunn.dll). This is a standard Microsoft component, so there will be no problems in using it within VBA.

The following function takes in the name of a file and returns the data the file was last accessed.

Function GetLastAccessed(ByVal strFile As String) As Date
Dim myFSO As Object
Dim myFile As Object

' instantiate reference to filesystemobject
Set myFSO = CreateObject("Scripting.FileSystemObject")
' assign file to memory
Set myFile = myFSO.GetFile(strFile)

' get DateLastAccessed
GetLastModified = myFile.DateLastAccessed
End Function

DateLastModified can be used in place of DateLastAccessed.

I hope this helps.

Schizo
 
Schizo, I was trying to use the code you posted here to check the DateLastAccessed on the active document (I'm using Word). The idea is, I want to compare it against a registry value and see which one is earlier. I can get the ActiveDocument.Name and store it in a string variable, but when I try to get any file data from it (DateLastAccessed, etc.) I get a "file not found" error. In fact, it looks like no matter what file name I pass to the function, I get the same "file not found" message.
Am I missing something?
 
I found a way to avoid using DateLastAccessed altogether, but thank you for the reply Dbaseguy. Your suggestion is probably correct anyhow. [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top