Hi there. I'm using the following code to move pdf and snp files into seperate locations after they have been used by another module. Purely for backup purposes. However if a user creates the same reports twice in one day for the same school the pdfs and snps are not placed into the folder as they already exist. As the users keep forgetting to delete the old versions the folder is starting to get a bit clogged! Please can you teach me how to replace the pdf and snp files if they already exist in the ToPath and ToPath2 locations? I've been trying for a while now and can't seem to find the right code/syntax to fit in with what I already have. I'm sorry to paste the whole code in - it's very short and basic anyways, just thought it might give you more context of what it's doing at the moment.
I really appreciate all your help. Thanks!
Code:
Sub Move_Certain_Files_To_New_Folder()
'This will move all Snapshot and PDF files from FromPath to ToPath.
'Note: It will create the folder ToPath for you with a date-time stamp
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim ToPath2 As String
Dim FileExt As String
Dim FileExt2 As String
Dim FNames As String
Dim MySchool As String
MySchool = [Forms]![Selector]![School]
'move snapshots into a new folder
FromPath = "U:\InvigReports"
ToPath = "U:\InvigReports\" & Format(Now, "dd-mm-yyyy") _
& " School " & MySchool & " SnapShots" & "\"
FileExt = "*.snp*"
If Right(FromPath, 1) <> "\" Then
FromPath = FromPath & "\"
End If
FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "No files in " & FromPath
Exit Sub
End If
Set FSO = CreateObject("scripting.filesystemobject")
FSO.CreateFolder (ToPath)
FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
'MsgBox "You can find the files from " & FromPath & " in " & ToPath
'move pdfs into a new folder
ToPath2 = "U:\InvigReports\" & Format(Now, "dd-mm-yyyy") _
& " School " & MySchool & " PDFs" & "\"
FileExt2 = "*.pdf*"
FNames = Dir(FromPath & FileExt2)
If Len(FNames) = 0 Then
MsgBox "No files in " & FromPath
Exit Sub
End If
Set FSO = CreateObject("scripting.filesystemobject")
FSO.CreateFolder (ToPath2)
FSO.MoveFile Source:=FromPath & FileExt2, Destination:=ToPath2
'MsgBox "You can find the files from " & FromPath & " in " & ToPath2
End Sub
Comment