Kill Script

A

Arturo

Can someone help me with this? I copied the code from the forum last week and
added the hyperlink and DoCmd.Quit commands. I was deleting .mdb files.
Sometimes there was one and sometimes there were many, and it always worked
great. I have since converted the files to .mde files. Now it only deletes
one .mde file. I can rerun it and it won’t delete any more files in that
directory.

Private Sub Form_Open(Cancel As Integer)
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("C:\ab c\new\*.mde") Then
Kill "C:\ab c\new\*.mde"
Else
End If

Application.FollowHyperlink "C:\ab c\MyProgram.mde"
DoCmd.Quit
End Sub

Thanks.
 
D

Dirk Goldgar

Arturo said:
Can someone help me with this? I copied the code from the forum last week
and
added the hyperlink and DoCmd.Quit commands. I was deleting .mdb files.
Sometimes there was one and sometimes there were many, and it always
worked
great. I have since converted the files to .mde files. Now it only deletes
one .mde file. I can rerun it and it won’t delete any more files in that
directory.

Private Sub Form_Open(Cancel As Integer)
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("C:\ab c\new\*.mde") Then
Kill "C:\ab c\new\*.mde"
Else
End If

Application.FollowHyperlink "C:\ab c\MyProgram.mde"
DoCmd.Quit
End Sub


Are you sure it was really working properly before? I don't *think* the
FileExists method accepts wild cards.

However, I don't see any reason you couldn't use this much simpler version:

'----- start of code -----
Private Sub Form_Open(Cancel As Integer)

If Len(Dir("C:\ab c\new\*.mde")) > 0 Then
Kill "C:\ab c\new\*.mde"
End If

Application.FollowHyperlink "C:\ab c\MyProgram.mde"
DoCmd.Quit

End Sub

'----- end of code -----

That's assuming you don't want to just execute the Kill statement without
any preliminary check, and just trap and ignore the error that will be
raised if no matching files exist.
 
H

Hans Up

Arturo said:
Can someone help me with this? I copied the code from the forum last week and
added the hyperlink and DoCmd.Quit commands. I was deleting .mdb files.
Sometimes there was one and sometimes there were many, and it always worked
great. I have since converted the files to .mde files. Now it only deletes
one .mde file. I can rerun it and it won’t delete any more files in that
directory.

Private Sub Form_Open(Cancel As Integer)
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("C:\ab c\new\*.mde") Then
Kill "C:\ab c\new\*.mde"

I doubt your FileExists expression can return True. Therefore, I don't
see how your Kill command can ever run.

Consider this example:

? fs.FileExists("C:\Access\wip\Db1.mdb")
True
? fs.FileExists("C:\Access\wip\*.mdb")
False

As far as I can tell, you need the path to a single file for FileExists
to return True; giving it a wild card path returns False.

Consider an approach based on the following (untested) code to delete
all mde files from C:\ab c\new\

Dim strWhichFile As String
strWhichFile = Dir("C:\ab c\new\*.mde")
Do While Len(strWhichFile) > 0
Kill strWhichFile
strWhichFile = Dir()
Loop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top