Error 75: VBA has issues when creating sharepoint list item attachment folder (1 Viewer)

CoffeeBunny

New member
Local time
Today, 15:52
Joined
Dec 1, 2014
Messages
4
Problem: I am moving SharePoint list items from one list to another. I need to bring the attachments along. I have code working that will move the list item, however the code I have for the attachments errors out when VBA tries to create the list item's attachment folder. The error I receive is error 75 Path/File access error. I'm not sure how to get past this, and I have had no luck researching this issue online.

I do not have access to Designer, Visual Studio, cannot use Access web databases, or anything else. All I have to use is a local access DB on my laptop, and site owner permissions to a SharePoint site I've been tasked to manage.

For reference, here is the function I wrote in its entirety. mkDir is where things go south. This function is called at the tail-end of an update/add sub moving a list item from one list to another in SharePoint:
Code:
Public Function ProcessListItemAttachments(SourceRowID As Integer, SourceAttachFolder As String, DestinationRowID As Integer, DestinationAttachFolder As String) As Boolean
ProcessListItemAttachments = False  'if we suceed in copying files - or if there aren't any to copy - this will be set to true at the end
Dim strFile As String

On Error GoTo WhatBroke
'The process is:
'1)Look and see if the SourceURL exists (not all list items have attachments, so we need to check)
'2)If it does exist, then see if the destination already has the folder created.
'3)With both Source and Destination folders, loop through file(s) from the source and copy to the destination. Overwrite existing files.
'*********************************************************
'Make sure the attachment folder paths end with '\'
    If Right(SourceAttachFolder, 1) <> "\" Then
        SourceAttachFolder = SourceAttachFolder & "\"
    End If
    If Right(DestinationAttachFolder, 1) <> "\" Then
        DestinationAttachFolder = DestinationAttachFolder & "\"
    End If
'Make sure the paths are correct, and an attachment folder was found
    If ((GetAttr(SourceAttachFolder) And vbDirectory) = vbDirectory) = False Then
        MsgBox "The source list does not appear to have an attachments folder at this location:" & vbCrLf & _
        SourceAttachFolder & vbCrLf & "Please check this folder path and try again", vbCritical + vbOKOnly, "Source Attachment Folder Not Found!"
        Exit Function
    ElseIf ((GetAttr(DestinationAttachFolder) And vbDirectory) = vbDirectory) = False Then
        MsgBox "The destination list does not appear to have an attachments folder at this location:" & vbCrLf & _
        DestinationAttachFolder & vbCrLf & "Please check this folder path and try again", vbCritical + vbOKOnly, "Destination Attachment Folder Not Found!"
        Exit Function
    End If
    'Change the sourcepath to look at the path for the specific list item. Attachment folders in SharePoint are named with the ID of the list item, ie ..\Attachments\12\.
    SourceAttachFolder = SourceAttachFolder & SourceRowID & "\"
    'Does this item ID have a folder? No means the item has no attachments, and we can nope out of this function.
    'Note than an item could have a folder with no files.  That means at some point in time it did have attachments, but they were deleted.
    If Len(Dir(SourceAttachFolder, vbDirectory)) = 0 Then
        ProcessListItemAttachments = True  'Nothing to copy, so it's all good
        Exit Function
    ElseIf Len(Dir(DestinationAttachFolder, vbDirectory)) > 0 Then  'We've got a folder. Now do some processing
        DestinationAttachFolder = DestinationAttachFolder & DestinationRowID & "\" 'where do the files need to be copied to?
        If Len(Dir(DestinationAttachFolder, vbDirectory)) = 0 Then
            MkDir DestinationAttachFolder 'if the destination attachment item folder doesn't yet exist, create it
        End If

strFile = Dir(SourceAttachFolder)
        Do While Len(strFile) > 0
            'Debug.Print "FileCopy source: " & SourceAttachFolder & strFile & ", destination: "; DestinationAttachFolder & strFile
            FileCopy SourceAttachFolder & strFile, DestinationAttachFolder & strFile
            strFile = Dir
        Loop
    
        ProcessListItemAttachments = True  'we made it to this point. All's good
    End If

exitblock:
    Exit Function
WhatBroke:
    If (Err.Number <> 0) Then
        MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & VBE.ActiveCodePane.CodeModule, vbOKOnly, "Error"
        DoCmd.Hourglass False
        Resume exitblock
    End If
End Function

Edit: The paths being passed into this function are pre-populated text boxes that users can change. The paths look like this: \\MySharePointSite\SourceList\Attachments\ and \\MySharePointSite\DestinationList\Attachments\. I'm also passing in the row IDs of the list items from both lists.
 
Last edited:

Users who are viewing this thread

Top Bottom