Link a database that has a changing file name based on date

  • Thread starter Thread starter jamesker
  • Start date Start date
J

jamesker

Hi,

I have a temporary database on a network drive that is saved weekly as
a new name based on it's save date, such as:

iTRKDAT_TMP_20080227.MDB
iTRKDAT_TMP_20080228.MDB
iTRKDAT_TMP_20080303.MDB

the system is currently set up so that every week when a new temporary
database is created, you need to manually go in and retrieve table
information from it. What i want to do is automatically link the
newest temporary database into a main database that will retrieve the
table information with the click of a button.

I've messed around with the docmd.transferdatabase function in VB but
i'm not sure how to get it to pick the filename with the most recent
date in it. If anyone out there could help me with this problem then
i'd greatly appreciate it.
 
Function ReturnNewestFile() As String

Dim strFolder As String
Dim strFile As String
Dim strDate As String
Dim strNewestDate As String

strFolder = "G:\Folder1\Folder2\"
strFile = Dir(strFolder & "*.mdb")
Do While Len(strFile) > 0
strDate = Mid$(strFile, 13, 8)
If strDate > strNewestDate Then
strNewestDate = strDate
End If
strFile = Dir()
Loop

ReturnNewestFile = strFolder & "iTRKDAT_TMP_" & _
strNewestDate & ".MDB"

End Function
 

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

Back
Top