G
Guest
Hi,
I have a problem getting the latest file of a series of files created. Each
week a number of files (can change each week) are created. I am unable to
change the naming convention. They are all in a path of
\\wpwss05\GrpData\XFERDATA\Reports\.
The filenames are:
SMSR_PLN_GEN_POL_XLS09092006_1_200609110531.txt
SMSR_PLN_GEN_POL_XLS09092006_2_200609110531.txt
SMSR_PLN_GEN_POL_XLS09092006_3_200609110531.txt
SMSR_PLN_GEN_POL_XLS09092006_4_200609110532.txt
SMSR_PLN_GEN_POL_XLS09092006_5_200609110532.txt
Looking in Windows Explorer the date modified for the above files are:
11/09/2006 5:32 AM
11/09/2006 5:32 AM
11/09/2006 5:32 AM
11/09/2006 5:33 AM
11/09/2006 5:33 AM
I am using the following code:
Private Sub Btn_Import_Files_Click()
Dim iResponse As Integer
Dim l_sFilename As String
l_sFilename = ""
SysCmd acSysCmdSetStatus, "Importing Data Files"
l_sFilename = getlatestfilename("SMSR_PLN_GEN_POL_XLS")
MsgBox ("The file selected was: " & l_sFilename)
DoCmd.Hourglass False
SysCmd acSysCmdSetStatus, " "
DoCmd.SetWarnings True
MsgBox "File(s) imported.", vbOKOnly, "File Import"
End Sub
Private Function getlatestfilename(p_sName As String)
With Application.FileSearch
.NewSearch
.LookIn = "\\wpwss05\GrpData\XFERDATA\Reports\"
.SearchSubFolders = False
.FileType = MsoFileType.msoFileTypeAllFiles
.PropertyTests.Add "File name", msoConditionEndsWith, ".txt"
.FileName = p_sName & "???????????????????????"
If .Execute(MsoSortBy.msoSortByLastModified,
MsoSortOrder.msoSortOrderDescending) > 0 Then
getlatestfilename = .FoundFiles(1)
Else
getlatestfilename = Empty
End If
End With
End Function
My problem is when I produce the results in the message box it ALWAYS gives
me the FIRST file (SMSR_PLN_GEN_POL_XLS09092006_1_200609110531.txt) as the
most recent. I'm pretty sure it should be
SMSR_PLN_GEN_POL_XLS09092006_5_200609110531.txt.
Any ideas?
Andrew 120906
I have a problem getting the latest file of a series of files created. Each
week a number of files (can change each week) are created. I am unable to
change the naming convention. They are all in a path of
\\wpwss05\GrpData\XFERDATA\Reports\.
The filenames are:
SMSR_PLN_GEN_POL_XLS09092006_1_200609110531.txt
SMSR_PLN_GEN_POL_XLS09092006_2_200609110531.txt
SMSR_PLN_GEN_POL_XLS09092006_3_200609110531.txt
SMSR_PLN_GEN_POL_XLS09092006_4_200609110532.txt
SMSR_PLN_GEN_POL_XLS09092006_5_200609110532.txt
Looking in Windows Explorer the date modified for the above files are:
11/09/2006 5:32 AM
11/09/2006 5:32 AM
11/09/2006 5:32 AM
11/09/2006 5:33 AM
11/09/2006 5:33 AM
I am using the following code:
Private Sub Btn_Import_Files_Click()
Dim iResponse As Integer
Dim l_sFilename As String
l_sFilename = ""
SysCmd acSysCmdSetStatus, "Importing Data Files"
l_sFilename = getlatestfilename("SMSR_PLN_GEN_POL_XLS")
MsgBox ("The file selected was: " & l_sFilename)
DoCmd.Hourglass False
SysCmd acSysCmdSetStatus, " "
DoCmd.SetWarnings True
MsgBox "File(s) imported.", vbOKOnly, "File Import"
End Sub
Private Function getlatestfilename(p_sName As String)
With Application.FileSearch
.NewSearch
.LookIn = "\\wpwss05\GrpData\XFERDATA\Reports\"
.SearchSubFolders = False
.FileType = MsoFileType.msoFileTypeAllFiles
.PropertyTests.Add "File name", msoConditionEndsWith, ".txt"
.FileName = p_sName & "???????????????????????"
If .Execute(MsoSortBy.msoSortByLastModified,
MsoSortOrder.msoSortOrderDescending) > 0 Then
getlatestfilename = .FoundFiles(1)
Else
getlatestfilename = Empty
End If
End With
End Function
My problem is when I produce the results in the message box it ALWAYS gives
me the FIRST file (SMSR_PLN_GEN_POL_XLS09092006_1_200609110531.txt) as the
most recent. I'm pretty sure it should be
SMSR_PLN_GEN_POL_XLS09092006_5_200609110531.txt.
Any ideas?
Andrew 120906