• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

How to Find a file and delete it using MSAccess 2007

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.

1 Solution
Patrick MatthewsCommented:
FIleSearch was dropped from Office 2007.

You could try this:

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now