如何克隆Access中的SharePoint列表附件字段

时间:2015-12-01 06:20:39

标签: vba ms-access sharepoint ms-access-2013

如何在Access 2013中克隆附件字段?它使用FileData字段给出了“无效参数”错误。

FileData在调试器中显示为Variant / Byte类型。看起来像一个字节数组。

我正在使用标准的SharePoint列表样式附件字段。

我见过的例子Copy An Attachment Field表明以下代码可以正常工作,但我收到“无效参数”的错误

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

1 个答案:

答案 0 :(得分:0)

这有效:

  • 。更新父记录。
  • 使用以下方法复制FileData字段:

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

在保存父记录之前,无法保存附件记录。另外要复制fileData字段,请使用GetChunk和AppendChunk

警告 - AppendChunk仅适用于第一个追加。之后所有追加都失败了。

虽然MS提供以下示例(请参阅https://msdn.microsoft.com/en-us/library/bb220958(v=office.12).aspx),但AppendChunk无法与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