I am using the File Copy to deploy upgrades to an application, and I am trying to catch instances where the copy fails because the User has the application open. I am trying to use this code to capture the failure:
FileCopy strFileCopyFrom, strFileCopyTo
If Err <> 0 Then
The Err is not capturing the error. I am resetting it to 0 before each copy attempt.
Is there a better method for catching the instances where the Copy fails?
I have successfully used just the "If Err <> 0" in other cases, notably when a User generated process tried to save over an Excel file that is already open.
I AM using the On Err Resume Next. (Actually, Jim, I think I may have gotten the code from you some time back!) And I am setting Err to Zero before each attempt so I don't inherit a previous fail.
The problem seems to be that if the copy fails, it is not changing Err from 0 to another value. I actually set up the first copy effort to a file I KNEW the user had open so I could throw the error and capture it. But when I walk through the code line by line and the File Copy runs but fails, the Err is remaining = 0 so I can't capture it.
Since "File Copy" is really just executing a DOS command (remember those days!) I'm afraid that - unlike an error that would occur inside the Access environment (like a run time error) - the failure of the File Copy command doesn't throw a value into the Err variable.
I can't use the approach of copying the new app down on login (which VB does - or did when I was using it) automatically because the app being copied is the one where the Login occurs. So - unless there is something I don't know about - the copy would ALWAYS fail because the file would be open when the File Copy command was called. So at the moment I am stuck with having to examine EACH destination folder to see if the new version copied over. I'm wondering if maybe there is some way to display each destination folder's contents - with the Date Stamp - so I could see any that were not the current version. A little klugy - but better than nothing.
John Tsioumpris
you can use a simple bat file for the copy on login
just xcopy source destination
It demonstrates how to use a shortcut and a script to avoid all the troubles like the one you are facing.
Buck Beasom
ASKER
Gustav. I am going to dig into what you provided. I'm pretty sure it will come in useful in a number of settings. Will get back to you as soon as I have completed my study. Thank you!
Anders Ebro (Microsoft MVP)
You could also look into using the FileSystemObject for your copy needs. It should have better error feedback: FileSystemObject CopyFile
Should be On Error Resume Next
Jim.