Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy a file from one location ot another

Status
Not open for further replies.

PercyN

Programmer
May 16, 2007
86
Hi,
I am trying to copy a file from one location to another. I found this code in VBA help but is returns an error that says object required.

Code:
Public Function CopyFile()
FileSystemObject.CopyFile Application.CurrentProject.Path & "\ldc.dll", "c:\Windows\System32\", True
End Function

Can anyone help?
 
Try with one of the native methods, in stead;

[tt]Public Function CopyFile()
FileCopy Application.CurrentProject.Path & "\ldc.dll", "c:\Windows\System32\ldc.dll"
End Function[/tt]

You might want to check if it's already there, for instance with the Dir() function (check help)

Roy-Vidar
 
Roy-Vidar,
Thanks for your reply. It still returns the same error. I have a separate function that checks if the file exits and the path is correct. That one works fine. But this this one is giving me a lot of headache
 
I can't see why (unless you've kept the original code somewhere, and perhaps work without Option Explicit at the top of each module).

You are sure it is that (my) above line of code giving the error? That the whole code is on one line? That the code is run in Access?

Try two more things
1 - rename the function to something that's not the name of an object, property or method (say MyCopyFile)
2 - prefix the FileCopy method

[tt]VBA.FileSystem.FileCopy CurrentProject.Path...[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top