?
Solved

MS Access Application.FileSearch

Posted on 2011-03-22
4
Medium Priority
?
448 Views
Last Modified: 2013-11-27
After searching I found the problem is that 07 no longer supports the .FileSearch function (which is stupid IMO).  Anyway, I have code that worked in 03.  It searches for .log files in a directory and if there are more than 10 files present, it deleted the oldest one.  What do I need to use in 07 to do this?

Here is the code that worked in 03.

Thank you!

Sub DeleteOldestFile()
'maintains the number of log files to a max of 10.  Deletes the oldest file.
    Dim strFilePath As String

    strFilePath = GetDBPath
   
    With Application.FileSearch
       .NewSearch
       .LookIn = strFilePath
       .Filename = "*.log"
       .Execute
       If .FoundFiles.Count >= MAX_LOG_COUNT Then
            Kill .FoundFiles(1)
       End If
    End With
   
End Sub

Open in new window

0
Comment
Question by:AronMcD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 35189762
you can try the File scripting, needs reference to Microsoft scripting runtime

codes goes something like this

Dim fso As Scripting.FileSystemObject
Dim srcFolder As Scripting.Folder
Dim fileItem As Scripting.File
Dim strFilePath As String

    strFilePath = GetDBPath

Set fso = New Scripting.FileSystemObject
Set srcFolder = fso.GetFolder(strFilePath)

    For Each fileItem In srcFolder.Files
        If Right(fileItem, 4) = ".log" Then
        Debug.Print fileItem.Name, fileItem.DateCreated
        End If
    Next
    

Open in new window

0
 

Author Comment

by:AronMcD
ID: 35190107
capricorn,
Using fileItem.Delete deletes all files with the .log extension.  How do I delete just the oldest file?  

Thanks for the help.

0
 

Author Comment

by:AronMcD
ID: 35190334
capricorn,
I got it to work using:

Kill strFilePath & fileItem.Name

Seems to work fine.....unless you know of a better way.

Thanks for the help.   I appreciate it.  
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35190534
sorry, just got back from a meeting. glad you got it working..
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question