Problems using CopyFile on FileSystem object

Posted on 2014-09-23
Last Modified: 2014-09-24

I have this code in VBA:

Dim fso As Object
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
fso.CopyFile(source, destination, true )

Open in new window

Where source and destination are the name of a file to be copyied and a file that already exists but should be replaced.

This worked before on a computer with Windows 7, but now it is installed on a new computer with Windows 8.1 and it doesn't work, but don't get any error too.

What could be happening?
Is this  away to detect an error if it is (for example a lag of permissions) ?

Any help would be appreciated. Thank you.
Question by:gplana
  • 2
  • 2
  • 2
  • +3
LVL 47

Accepted Solution

Dale Fye (Access MVP) earned 500 total points
ID: 40340172
Is this being run from within Access or Visual Basic?

In Access, I don't usually bother with the file scripting object, I usually use:

IF Dir(Destination) <> "" Then Kill Destination
filecopy source, destination
LVL 12

Expert Comment

ID: 40340175
Do you have error handling in place?

On Error Goto ErrHandler

MsgBox Err.Number & " " & Err.Description

Open in new window

LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40340178
Sometimes I'll rename the destination file if it already exists, then do the copy operation, and then delete the old (renamed) file if the FileCopy operation succeeds.

Expert Comment

ID: 40340186
Does it work if the files do not exist?

I would delete the files first and see if it copies the files successfully.  You need to find out if Win 8 is even letting the script run at all.

Also, what folder are you trying to copy files to?
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

LVL 15

Author Comment

ID: 40340187
I'ts made in Access, but it worked before.
I had to say that before it was Access 2007 and now it is Access 2013. Could this affect ?
I don't have on error statement. Should I add it?
LVL 33

Expert Comment

ID: 40340197
What are the source and destination?

Have you checked that you have permission to read/write to the folder(s) they point to?
LVL 12

Expert Comment

ID: 40340199
I'ts made in Access, but it worked before.
 I had to say that before it was Access 2007 and now it is Access 2013. Could this affect ?

It might, but I am not able to verify this.

I don't have on error statement. Should I add it?
I think it is always good to add it, however if you got an error and you don't have an error handler in place, it should still pop-up. It's just a better way to handle errors. So I am not sure what's going on.

Do you have any missing references in your Access Database?
Check Tools > References > MISSING ?

LVL 75
ID: 40340264
fso.CopyFile(source, destination, true )

Seems this should be:

fso.Copy (source, destination, true )

I don't think there is CopyFile in the FSO object.

LVL 75
ID: 40342269
I use FSO all the time, considering it's VERY powerful.


Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now