0

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
Erik A
  • 31,639
  • 12
  • 42
  • 67
EbayBill
  • 55
  • 1
  • 8
  • 1
    Get rid of that trailing space in `Path`. (Theoretically `Path` shouldn't even have the trailing backslash either, and then you should use `Path & "\" & Foldername` everywhere you currently use just `Path & Foldername`.) – YowE3K Dec 06 '17 at 20:01
  • I have never seen a double slash in the *middle* of a Windows file path, only at the **beginning** of a [UNC](https://msdn.microsoft.com/en-us/library/gg465305.aspx) path. – Parfait Dec 06 '17 at 20:35
  • I figured it out. My row Current Year (Me.CntYr) was Null except for the first record... – EbayBill Dec 06 '17 at 21:43

0 Answers0