Retrieve most recent file

D

Daniel P

Hello

I currently use the following line of code to identify a specific file to be able to back it up automatically

SourceFile = "\\Pointeclaire\Public\CAMTA Database\BackEnd\CAMTA_be V02 R06.mdb"

However, as you can see there have been and are go to be many revision to the database file in question. How can I code it so that I no longer am required to keep changing the source file manually? What coding will retrieve the file "...\CAMTA_be Vxx Ryy.mdb" where xx and yy would be the greatest values that the computer can identify in the directory in question

Thanking you in advance for your help

Daniel
 
S

solex

You could do a number of things. All of which relate to using the Dir()
command to (1) loop through and parse the version number out so you can
compare it to the other versions or (2) check the file date persumably the
file with the latest date will also be the most recent version (an
assumption on my part)

Regards,
Dan


Daniel P said:
Hello,

I currently use the following line of code to identify a specific file to
be able to back it up automatically:
SourceFile = "\\Pointeclaire\Public\CAMTA Database\BackEnd\CAMTA_be V02 R06.mdb"

However, as you can see there have been and are go to be many revision to
the database file in question. How can I code it so that I no longer am
required to keep changing the source file manually? What coding will
retrieve the file "...\CAMTA_be Vxx Ryy.mdb" where xx and yy would be the
greatest values that the computer can identify in the directory in question?
 
E

Elwin

Paste this function into a new module and call it like
this...

eg) x = GetRecentfile("C:\", "CAMTA")


Function GetRecentFile(strPath As String, strClient As
String) As String
Dim strName As String
Dim iMaxVer As Integer
Dim iMaxRev As Integer
Dim v As Integer
Dim r As Integer
strClient = strClient & "_be"
strName = Dir(strPath, vbDirectory)
Do While strName <> ""
If Left(strName, 1) = "~" Then
ElseIf (GetAttr(strPath & strName) And _
vbDirectory) = vbDirectory Then
ElseIf InStr(strName, strClient) > 0 Then
v = Mid(strName, Len(strClient) + 3, 2)
If v > iMaxVer Then iMaxVer = v
r = Mid(strName, Len(strClient) + 7, 2)
If r > iMaxRev Then iMaxRev = r
End If
strName = Dir
Loop
GetRecentFile = strPath & strClient _
& " V" & Format(v, "00") _
& " R" & Format(r, "00") & ".mdb"
Exit Function
End Function

-----Original Message-----
Hello,

I currently use the following line of code to identify a
specific file to be able to back it up automatically:
SourceFile = "\\Pointeclaire\Public\CAMTA
Database\BackEnd\CAMTA_be V02 R06.mdb"
However, as you can see there have been and are go to be
many revision to the database file in question. How can I
code it so that I no longer am required to keep changing
the source file manually? What coding will retrieve the
file "...\CAMTA_be Vxx Ryy.mdb" where xx and yy would be
the greatest values that the computer can identify in the
directory in question?
 
E

Elwin

I screwed up and used the wrong variables in the last
line. Substitute this...


GetRecentFile = strPath & strClient _
& " V" & Format(iMaxVer, "00") _
& " R" & Format(iMaxRev, "00") & ".mdb"
 

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