Access 2016- Code works perfect on the first Record in the Recordset. I get Run-time 76 error "path not found" for any record after the first on this line.
objFSO.CopyFile myfile, Path & Foldername & "\"
Not sure if this is the problem - The Path is correct but has \ \ on the back end (C:\xxx\ \ ), but '& "\"
causes it to write the folder name as a file.
I've changed the Paths, Folders and everything else and got the same results.
Full Code:
Private Sub CreatePath_Click()
Dim objFSO As Object
Dim objFile As Object
Dim openDialog As FileDialog
Dim Foldername As String
Dim Path As String
Dim i As Integer
Foldername = DLookup("CustomLabelCombine", "[Inventory]", "
[CustomLabelCombine]= Forms![Items to List]!SKU2")
Path = "Z:\Ebay\Suppliers Inventory\" & Me.CntYr & "\ "
Set openDialog = Application.FileDialog(msoFileDialogFilePicker)
openDialog.AllowMultiSelect = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
If openDialog.Show = -1 Then
If Dir(Path, vbDirectory) = vbNullString Then
MkDir Path
MkDir Path & Foldername
End If
For i = 1 To openDialog.SelectedItems.Count
myfile = openDialog.SelectedItems.Item(i)
objFSO.CopyFile myfile, Path & Foldername & "\"
Next
MsgBox "Files were successfully copied"
End If
Set objFSO = Nothing
Set openDialog = Nothing
End Sub