?
Solved

Problems using CopyFile on FileSystem object

Posted on 2014-09-23
9
Medium Priority
?
176 Views
Last Modified: 2014-09-24
Hi.

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.
0
Comment
Question by:gplana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 48

Accepted Solution

by:
Dale Fye earned 2000 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
0
 
LVL 12

Expert Comment

by:danishani
ID: 40340175
Do you have error handling in place?

On Error Goto ErrHandler
'...
ErrHandler:

MsgBox Err.Number & " " & Err.Description

Open in new window

0
 
LVL 48

Expert Comment

by:Dale Fye
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.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 3

Expert Comment

by:Jerry_Justice
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?
0
 
LVL 15

Author Comment

by:gplana
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?
0
 
LVL 34

Expert Comment

by:Norie
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?
0
 
LVL 12

Expert Comment

by:danishani
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 ?

Daniel
0
 
LVL 75
ID: 40340264
RE:
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.

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

m
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

762 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