How to copy a file in Access?

A

Amit

Hi,

I'm having some problem copying a file using code in the form's OnOpen event.
Here's the code snippet:
===========================================================
Dim fs, a
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.copyfile("C:\Access Databases\readme.doc", "C:\Security\")
=========================================================

I get a run-time error of "type mismatch" at "set a = ..." line.

I've tried a variation of this with
Dim fs, a as FileSystemObject
with the same results.

I've checked the MS help file and it seems like the syntax is correct.

Will appreciate any help with this.

Thanks.

-Amit
 
I

Immanuel Sibero

Hi Amit,


Try the FileCopy in VBA

FileCopy SourceFile, DestinationFile

I vaguely remember you from previous post. Someone suggested using the
FileSystemObject which is an overkill to do simple things such as make new
folders, delete files, copy files.. etc.



HTH,
Immanuel Sibero
 
W

Wayne Morgan

Try dropping the "set a =" part and just use the rest of the line. You may
also want to check out the VBA FileCopy statement.
 
M

Marshall Barton

Amit said:
I'm having some problem copying a file using code in the form's OnOpen event.
Here's the code snippet:
===========================================================
Dim fs, a
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.copyfile("C:\Access Databases\readme.doc", "C:\Security\")
=========================================================

I get a run-time error of "type mismatch" at "set a = ..." line.

I've tried a variation of this with
Dim fs, a as FileSystemObject
with the same results.

I've checked the MS help file and it seems like the syntax is correct.


Skip the FileSystemObject and just use Access FileCopy
statement.
 
A

Amit

Thanks, guys.
Wow, FileCopy is so much simpler. I tried it and it works great!!

Have a nice day!

-Amit
 
Top