How do I copy a file via VBA from one folder to another? Currently getting Error 424 (1 Viewer)

Cark

Registered User.
Local time
Today, 07:20
Joined
Dec 13, 2016
Messages
153
I have an Access Database which has a bit of VBA code which aims to take a file on a user's desktop and send it to a shared I: drive on the network with the filepath being saved in the database.

sPath, sFile and savePathDirectory are all set up to be Strings, however I cannot seem to be able to get it to work with the code below when I replace the terms with "sPath & sFile" and "savePathDirectory":

Code:
FileSystemObject.CopyFile "c:\mydocuments\*\R1???97.xls", "c:\tempfolder"

When I run the code with FileSystemObject.CopyFile sPath & sFile, savePathDirectory I get Run-time error 424 Object required.

When running the Debug.Print for the various terms I get:

sPath & sFile = C:\Users\Cark\Documents\Pump & Motor Issues.docx

savePathDirectory = I:\SharedFolder\TestingFolderForDatabaseCopying\32523\

Any suggestions on how to solve / a better technique to use?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:20
Joined
May 7, 2009
Messages
19,230
you need to create a filesystem object first:

dim fsObject As Object
set fsObject = CreateObject("Scripting.FileSystemObject")
fsObject.CopyFile "c:\mydocuments\*\R1???97.xls", "c:\tempfolder\filename.xls"
set fsObject = Nothing
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:20
Joined
Oct 29, 2018
Messages
21,457
Hi. You could also try the VBA FileCopy statement.
 

Users who are viewing this thread

Top Bottom