FileCopy Working 80% of Time

S

Sash

I've created a database that reformats client files into a universal import
format. Basically, the user selects a file and based on the client I run a
few queries to parse names and then run the file through a program to formats
the data. At the end, I do a file copy to archive the file and then kill to
delete the original from the import directory. This works 80% of the time,
but I get "Run-time error 70" Permission Denied the other 10%. Oddly enough,
when I set breakpoints it never errors.

One thing I did notice is that this only seems to be occuring for the files
that I run through Monarch via a batch program. Again, the odd thing is that
sometimes it even works for these files. Is there a way to make sure the
file is closed before I try to kill it? Below is the code that I'm using and
I also tried to use Name, also below.

Of course, I need this fixed by Thursday so any suggestions or help would be
greatly appreciated.

Regards,
Sash

***NewNameFSN and strOrigFile are delared earlier in program****

'Move File to Archive
Dim strFile As String
Dim strMove As String
strFile = "u:\interfaces\import\FSHN.txt"
strMove = "u:\interfaces\import\archive\FSH\" & Format(Time, "HHMMSS") &
"_" & strOrigFile
Name strFile As strMove
Kill "u:\interfaces\import\FSHN.txt"
MsgBox "FSH moved to Archive."

** Also tried ***
FileCopy NewNameFSN, "u:\interfaces\import\archive\FSH\" & Format(Time,
"HHMMSS") & "_" & strOrigFile
Kill "u:\interfaces\import\FSHN.txt"
 
T

Tom van Stiphout

On Tue, 13 May 2008 06:40:02 -0700, Sash

Are you saying Monarch may still have the files open? That's a recipe
for disaster.
You may want to try to get exclusive access to the file before
proceeding. Try the Open statement with the Lock Read Write value for
the lock argument. If it fails, some other process has the file open.

-Tom.
 
S

Sash

Monarch is closed and done with the file, but it was just a guess. Can you
tell me what is the syntax for opening with read write value.
 
S

Sash

Me again. I moved the MsgBox to the line between FileCopy and Kill and it
seems to work. Does this make sense??
 
D

Douglas J. Steele

Since MsgBox requires the user to respond, you're introducing a delay which
may be enough for the operating system to complete whatever it's doing. What
I don't understand, though, is why your code works at all! The Name
statement renames a file. That means file "u:\interfaces\import\FSHN.txt"
should no longer exist: you're renamed it! That means the Kill statement
should raise an error.
 
S

Sash

Thanks Doug. Sorry about that I wasn't clear in my original post. I was
trying both FileCopy in which I then Kill the file, but when this wasn't
working correctly I tried Name instead. Which would you recommend to use in
my situation?? Name?
 
D

Douglas J. Steele

Since you're trying to rename a file, using the Name statement would appear
to be the appropriate way.
 

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