How to Copy Files to a Folder?

dwcolt

Registered User.
Local time
Today, 09:16
Joined
Apr 23, 2010
Messages
15
My previous post on this may have been overly complicated, so here is the simplified version.

I have a table that contains hyperlinks to various files. I want to write a simple script that will take each hyperlink and then copy the actual file into a pre-specified folder.

If anyone could point me in the right direction on this, it sure would be appreciated. Thanks in advance!
 
My previous post on this may have been overly complicated, so here is the simplified version.

I have a table that contains hyperlinks to various files. I want to write a simple script that will take each hyperlink and then copy the actual file into a pre-specified folder.

If anyone could point me in the right direction on this, it sure would be appreciated. Thanks in advance!

Presuming the hyperlink is the filepath:

Code:
dim rst
dim FSO
dim theFilePath
dim theFolder
the Folder = "YourFOlderLOcation" 'e.g "C:\tempfolder\"
set FSO = createobject("Scripting.FilesystemObject")
set rst = currentdb.openrecordset("YourTableName")
rst.movefirst
do until rst.EOF
   thefilepath = rst!YourFieldName
   if  fso.fileexists(thefilepath) then
       fso.copyfile(thefilepath,theFolder,true)
  end if
  rst.movenext
loop
 
Fantastic. I was tinkering with this and getting very close to that solution. Thanks so much!!
 
Ok, follow up problem. I am using this script to upload files to a remote tablet.

When I map a network drive to the tablet using the tablet's IP address, the file copies over just fine with the drive letter as the upload path.

But I want to be able to upload directly to an IP address without mapping to a network drive. This is because this script is used to upload documents to multiple tablets, and it's not practical to map each one of those as a separate drive.

I've tried every combination of filepath:
h ttp://10.0.1.20 (had to put in space because i'm a newbie and can't post links)
h ttp://10.0.1.20/
file://10.0.1.20
file://10.0.1.20/
\\10.0.1.20
\\10.0.1.20/

No luck. It says either "path not found" or "invalid path". Any thoughts?
 
Got it working like a charm! Thanks so much for the insight. Here's the final code:

Private Sub UploadToIpad_Click()
On Error GoTo Form_Error

If IsNull(Me.TimekeeperName) = True Then
MsgBox "Select an available timekeeper to begin the upload.", 0, "CW Case Management System"
Else
DoCmd.OpenForm "UploadProgressForm"
DoEvents

Dim MyDB As Database
Dim MyRS As Recordset
Dim fs As Object
Dim objNetwork
Dim strDriveLetter, strRemotePath, sortpath, filename

strDriveLetter = "I:"
strRemotePath = "\\" & Me.RemoteUploadPath1
Set objNetwork = CreateObject("WScript.Network")
Set fs = CreateObject("Scripting.FileSystemObject")
If (fs.DriveExists("I:")) = True Then
Else
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
End If

Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("CheckForMarkedQuery")
MyRS.MoveFirst

Do Until MyRS.EOF
filename = MyRS![FilePath]
sortpath = MyRS![MatterName] & "\" & MyRS![SortCategory]
filename = Replace(filename, "file:", "")
MkDirs (strDriveLetter & sortpath)
fs.CopyFile filename, strDriveLetter & "\" & sortpath & "\"
MyRS.MoveNext
Loop

End If
MsgBox "The Selected Files Have Been Successfully Uploaded.", 0, "CW Case Management System"

Form_Error:
Select Case Err.Number
Case -2147024843
MsgBox "The remote device could not be located on the network. Check the IP address and make sure that the Document Manager is open and running on the remote device.", 0, "CW Case Management System"

End Select
End Sub
 

Users who are viewing this thread

Back
Top Bottom