Hey the Community,
My code blocks at the line level "MkDir ToPath"
He don't find the ToPath directory
My code blocks at the line level "MkDir ToPath"
He don't find the ToPath directory
Code:
Option Compare Database
Function Copy_Some_files()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sSQL As String
Dim i As Long
Set db = CurrentDb
sSQL = " SELECT Numero, Matr" & _
" FROM Decisions" & _
" Where Numero > '999'"
Set rs = db.OpenRecordset(sSQL, dbOpenSnapshot)
With rs
If rs.RecordCount = 0 Then
MsgBox "No files to transfer"
Else
Do While Not .EOF
FromPath = "C:\Decisions\"
ToPath = "C:\Pers\"
FileExt = ".pdf"
FromPath = FromPath & !Numero & FileExt
If Dir(FromPath) = "" Then
MsgBox FromPath & " doesn't exist"
Else
ToPath = ToPath & !Matr & "\"
If Dir(ToPath) = "" Then
MkDir ToPath
End If
FileCopy FromPath, ToPath & !Numero & FileExt
.MoveNext
End If
Loop
MsgBox "Files transferred from C:\Decisions to C:\Pers"
End If
End With
rs.Close
Set rs = Nothing
Set db = Nothing
End Function