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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locate Newest File that Contains "Alert" 1

Status
Not open for further replies.

Accel45

Technical User
Jul 7, 2004
83
US
I am using the following Function to retrieve the newest file in a folder. This is working fine.
However, I need to modify this function so that it will find the newest file in a folder where the file name contains "Alert". Any help would be appreciated.

Thanks
Accel45

Function Main()

Dim oFolder

Set oFolder = CreateObject("scripting.filesystemobject").getfolder("c:\test")
For Each aFile In oFolder.Files
If sNewest = "" Then
Set fNewest = aFile
sNewest = aFile.Name
Else
If fNewest.DateCreated < aFile.DateCreated Then
Set fNewest = aFile
End If
End If
Next

Me.Text1 = fNewest.Name

End Function
 
Code:
...
For Each aFile In oFolder.Files
  [!]If aFile Like "*Alert*" Then[/!]
    If sNewest = "" Then
...
    End If
  [!]End If[/!]
Next
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you PH, this worked great.
Accel45
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top