How to Find a file and delete it using MSAccess 2007

Posted on 2008-11-09
Last Modified: 2013-12-25
I'm trying to use MSAccess 2007 vba to find and delete a file if it exists, but when I tried to run it I get
"Run-time error '2455'; You entered an expression that has an invalid reference to the property FileSearch". I did some reading in some of the articles here and there was some mention that the Filesearch reference may no longer be available in access 2007. How else can I write this? Below is
the current code I scavenged together -

Set WB = Application.FileSearch
With Application.FileSearch
Lookin = "C:\Directory"
.FileName = "File.xls"
   If .Filename > 0 Then
      Kill ("C:\Directory\File.xls")
   End If
End With

I may also need a 'Else If' somewhere before the script end to tell the vba code to skip this step if the file
is not found otherwise I may get a 'File not Found" error.

Question by:benchok02
    1 Comment
    LVL 92

    Accepted Solution

    FIleSearch was dropped from Office 2007.

    You could try this:

    On Error Resume Next
    Kill "C:\Directory\FIle.xls"
    On Error GoTo 0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now