UTSWPeds
asked on
How can I use FileSystemObject in Access 2007 to confirm that a file has been copied sucessfully?
I have a command button in a MS Access 2007 Database that I use to copy a file. I want to confirm that the file has copied successfully, and I think FileSystemObject is the best way to do it. My command button executes the following line of code on after the On Click event:
FileCopy "C:\Folder1\Retirement.xls x", "C:\Folder1\Retirement_Cop y.xlsx"
After this line of code is run, I want to run a program that searches C:\Folder1 to validate that Retirement_Copy.xlsx exists. It it does exist, I'd like to have a message box that tells the user that the file copied successfully.
If it does NOT exist, I'd like a message box to inform the user that the file did not copy successfully.
Thanks. I'm getting better with VBA build in functions, but still have a long way to go.
FileCopy "C:\Folder1\Retirement.xls
After this line of code is run, I want to run a program that searches C:\Folder1 to validate that Retirement_Copy.xlsx exists. It it does exist, I'd like to have a message box that tells the user that the file copied successfully.
If it does NOT exist, I'd like a message box to inform the user that the file did not copy successfully.
Thanks. I'm getting better with VBA build in functions, but still have a long way to go.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here's the function I use:
'Determine whether or not a file exists at the given path
Public Function FileExists(filePath) As Boolean
On Error GoTo Error_Handler
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
FileExists = fs.FileExists(filePath)
Clean_Up:
Set fs = Nothing
Exit Function
Error_Handler:
msgbox err.descriptoin
FileExists = False
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This works. My preference would have been to have something purely done with Build-In funtions and contained within the On Click event of the command button (instead of building a function to call later in the process, as I'm not to the level of writing my own functions yet) but this solution did work very effectively.
Points were split, but it was greatly appreciated how Torrwin gave a little more explaination and direction than just the code, as that helped me know how to properly implement his instructions. For my level of VBA knowledge, this was very important.
Points were split, but it was greatly appreciated how Torrwin gave a little more explaination and direction than just the code, as that helped me know how to properly implement his instructions. For my level of VBA knowledge, this was very important.
ASKER
If Dir("C:\Folder1\Retirement
MsgBox "File Did Not Copy - Please be sure that the source file is not already open or in use by another program"
Else
MsgBox "File Copied Successfully"
End If
I tested it by having the "source" file open when I clicked the button and it didn't give me the first MsgBox, as I suspected, it gave me a "Permission Denied" warning.