Linked File Date and Time (1 Viewer)

tanyamc

Registered User.
Local time
Yesterday, 20:07
Joined
Mar 7, 2019
Messages
43
Is there a way to print the date/time information from a linked to file on a report?

Example: The linked file was updated yesterday, and has a Windows Explorer date/time of 03/17/19 12:01 PM. I'd like that info to print on my report so they now how current the data is on the report, rather than when the report was run.

Thanks.
 

isladogs

MVP / VIP
Local time
Today, 03:07
Joined
Jan 14, 2017
Messages
18,216

Ranman256

Well-known member
Local time
Yesterday, 22:07
Joined
Apr 9, 2015
Messages
4,337
If the xl file is linked, add this code to a module,
then submit the name of the table to get the date of the file linked to it.
put this in a text box, and run a query/report using the text box date.

getLinkedTblModDate("xlTest")

Code:
Public Function getFileModDate(ByVal pvFile)
getFileModDate = FileDateTime(pvFile)
End Function


Public Function getLinkedTblModDate(ByVal pvTbl)
Dim vLink
Dim i As Integer

 vLink = CurrentDb.TableDefs(pvTbl).Connect
 If vLink <> "" Then
    i = InStrRev(vLink, "=")
    If i > 0 Then
       vFile = Mid(vLink, i + 1)
       getLinkedTblModDate = getFileModDate(vFile)
    End If
 End If
End Function
 

tanyamc

Registered User.
Local time
Yesterday, 20:07
Joined
Mar 7, 2019
Messages
43
I have shared this with a coworker with much more experience to try...it's over my head! She may be chiming in. Thanks.
 

sxschech

Registered User.
Local time
Yesterday, 19:07
Joined
Mar 2, 2010
Messages
792
These are the functions I have been using (not sure how it compares to the other solutions):
Code:
Function LinkedTableModifiedDate(LinkedName As String)
'Obtain the file modified date based on the linked
'table's name.  Parse out the full path from the
'table def and then pass it to ModifiedDate function
'that uses FSO
'https://stackoverflow.com/questions/1742450/ms-access-linked-tables-how-to-get-the-connection-string-when-linked-table-ma
'20181231
    LinkedTableModifiedDate = ModifiedDate(Mid(CurrentDb.TableDefs(LinkedName).Connect, InStr(CurrentDb.TableDefs(LinkedName).Connect, "Database=") + 9) & "\" & CurrentDb.TableDefs(LinkedName).SourceTableName)
End Function
Code:
Public Function ModifiedDate(FullPath As String) As Date
'https://stackoverflow.com/questions/35082120/vba-accessing-a-csvs-creation-date
'20181231
'NOTE: an alternative to get the Creation Date is to use the
'      FileDateTime("filename.txt") function found at:
'https://www.techonthenet.com/access/functions/file/filedatetime.php
'      Not implenting that version in the qryFILES because still
'      using the LinkedTableCreationDate function in order to derive
'      the filename and path
'20190104
    ModifiedDate = CreateObject("Scripting.FileSystemObject").GetFile(FullPath).DateLastModified
    'Other options: DateCreated, DateLastModified, DateLastAccessed
End Function

This is how it was used in a query:
Code:
CSVDate: linkedtablemodifieddate("yourTableName")
In a report textbox probably like:
Code:
=linkedtablemodifieddate("yourTableName")

Also, as I found out when setting these up, if the file uses the same name as a previously named file, it will inherit the date information of that file unless there is a delay such as 15-20 seconds between when the file was renamed or deleted.
https://www.access-programmers.co.uk/forums/showthread.php?t=304114
 

Users who are viewing this thread

Top Bottom