How to clone the SharePoint list attachment field in Access

How to clone attachment Field in Access 2013? It gives me an "Invalid argument" error, with the FileData field.

FileData shows in the debugger as type Variant/Byte. And looks like an array of bytes.

I am using a standard SharePoint list style attachment field.

Examples I have seen Copy An Attachment Field suggest the following code will work, but I get an error of "Invalid argument"

Public Sub copyAttachment(recordsetMoveAttachmentFrom As DAO.Recordset2, recordsetMoveAttachmentTo As DAO.Recordset2)

      Do While recordsetMoveAttachmentFrom.EOF = False
        recordsetMoveAttachmentTo.AddNew
        recordsetMoveAttachmentTo!FileFlags = recordsetMoveAttachmentFrom!FileFlags
        recordsetMoveAttachmentTo!FileName = recordsetMoveAttachmentFrom!FileName
        recordsetMoveAttachmentTo!FileTimeStamp = recordsetMoveAttachmentFrom!FileTimeStamp
        recordsetMoveAttachmentTo!FileType = recordsetMoveAttachmentFrom!FileType
        recordsetMoveAttachmentTo!FileURL = recordsetMoveAttachmentFrom!FileURL
        recordsetMoveAttachmentTo!FileData = recordsetMoveAttachmentFrom!FileData            recordsetMoveAttachmentTo.Update
        recordsetMoveAttachmentFrom.MoveNext
      Loop

      Set recordsetMoveAttachmentFrom = Nothing 'Clear the Record set
      Set recordsetMoveAttachmentTo = Nothing 'Clear the Record set

End Sub

Answers


This worked:

  • .Update the parent record.
  • copy FileData field using:

      lngOffset  = 0
      conChunkSize = fldSource.FieldSize
      chunk = fldSource.GetChunk(lngOffset, conChunkSize)
      fldDestination.AppendChunk chunk
    

It is not possible to save the attachment record until the parent record has been saved. Also to copy the fileData field use GetChunk and AppendChunk

Warning - AppendChunk only worked with the first append. After that all appends failed.

While MS provide the below example (see https://msdn.microsoft.com/en-us/library/bb220958(v=office.12).aspx) AppendChunk does not look to work correctly with Access 2013

   ' Set size of chunk in bytes.
   Const conChunkSize = 5& * 1024 * 1024

   Dim lngOffset As Long
   Dim lngTotalSize As Long
   Dim chunk As Variant

   ' Copy the photo from one Recordset to the other in 32K
   ' chunks until the entire field is copied.
   lngTotalSize = fldSource.FieldSize
   Do While lngOffset < lngTotalSize
      chunk = fldSource.GetChunk(lngOffset, conChunkSize)
      fldDestination.AppendChunk chunk
      lngOffset = lngOffset + conChunkSize
   Loop

Need Your Help

Power of two textures

opengl texture-mapping

Can you explain me, why hardware acceleration required for a long time textures be power of two? For PCs, since GeForce 6 we achieved npot textures with no-mips and simplified filtering. OpenGL ES ...

PyQt widget keyboard focus

python pyqt pyqt5 keypress arrow-keys

First off -- thanks for this group! I started delving into PyQt a month or so ago. In that time, I've bumped up against many questions, and virtually always found an answer here.