Problem deleting a .txt file

T

T''Kai

I have developed a series of steps to deploy new front-ends to my users. Part
of the process involves creating a temporary .txt file (TBR.txt) in the same
directory as the replaced front-end. Once the front-end has been replaced I
attempt to delete the .txt file, but it fails.

The .txt file should be removed on the opening of a special mdb file. This
is where the code fails. However, if I create a form and placed the same code
behind a command button, it delete the .txt file perfectly.

Why does this code work behind a command button and not on the open event of
a form?

Here's the code:

strPath = CurrentProject.Path & "\"
strTBR = strPath & "TBR.txt"
If Dir(strTBR) <> "" Then Kill strTBR

Any help would be appreciated. Thank you.
 
G

Gigamite

T''Kai said:
I have developed a series of steps to deploy new front-ends to my users. Part
of the process involves creating a temporary .txt file (TBR.txt) in the same
directory as the replaced front-end. Once the front-end has been replaced I
attempt to delete the .txt file, but it fails.

The .txt file should be removed on the opening of a special mdb file. This
is where the code fails. However, if I create a form and placed the same code
behind a command button, it delete the .txt file perfectly.

What error message do you get when the code runs in the form's open event?
 
G

Gigamite

T''Kai said:
No error message. It just does nothing.

That shouldn't happen unless system messages are turned off. Look in
the code and macros for SetWarnings. Do you have any? The practice of
turning system messages on and off should be avoided, but it's fairly
common in Access databases.

The code may be failing in the form open event because the text file is
still locked from another process. You may have to put a slight time
delay in before running the file delete code.
 
T

T''Kai

I will try the time delay. Strangely, I have found that if I put the text
file into a seperate folder and still read it as I have been, I can delete it
from this new folder. The problem then becomes deleting the folder.
 
G

Gigamite

T''Kai said:
I have found that if I put the text
file into a seperate folder and still read it as I have been, I can delete it
from this new folder. The problem then becomes deleting the folder.

What's the problem? Another silent failure when deleting the folder?
 
T

T''Kai

Yes, but I think this may be because it thinks the folder is in use. Any
suggestions.
 

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