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

How do I Check for and Delete Existing File? 1

Status
Not open for further replies.

arachnoid

Programmer
Jun 14, 2002
108
US
Here is the code I have as of now, but I am getting an error message that says I still need an "object".

If Dir(&quot;C:\ASAM Files\Interchange Files\interchange_test_2.dbf&quot;) <> &quot;&quot; Then
file.deletefile (&quot;C:\ASAM Files\Interchange Files\interchange_test_2.dbf&quot;)
End If

Any help will be appreciated.

Thanks
 
Hi,

Try this
Code:
    If Dir(&quot;C:\ASAM Files\Interchange Files\interchange_test_2.dbf&quot;) <> &quot;&quot; Then
        Kill (&quot;C:\ASAM Files\Interchange Files\interchange_test_2.dbf&quot;)
    End If


Skip,
Skip@TheOfficeExperts.com
 
Well, I thought it was Excellent. I am now getting a run time '70' error. Permission Denied.

Any other suggestions?
 
It worked the first time, then I started getting this error.
 
Also, neither the file nor the folder are protected.
 
Try this:

IF LEN(DIR(&quot;C:\ASAM Files\Interchange Files\interchange_test_2.dbf&quot;)) > 1 Then
Kill (&quot;C:\ASAM Files\Interchange Files\interchange_test_2.dbf&quot;)
End If

I have had similar results until I tried this method.
 
Like the first method, this one worked the first time, then errored out the second. The error message was the same.

Is there some sort of error handling I could use here?
 
I figured it out...

The second time I was execute the macro, I was actually executing it within the .dbf file that I just saved instead of the .xls file.

The Permission Denied error was due to the fact the the file I was trying to overwrite was open...

In the words of Forrest Gump...&quot;I am not a smart man.&quot;
 
You might try:

On error resume next
Kill (&quot;C:\ASAM Files\ InterchangeFiles\interchange_test_2.dbf&quot;)

Glenn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top