How to copy a file in Access?


G

Guest

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
 
Ad

Advertisements

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.
 
Ad

Advertisements

G

Guest

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

Have a nice day!

-Amit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top