适用于:Access 2013、Office 2013
返回 Recordset 对象的 Fields 集合中备注或长 BinaryField2 对象的全部或部分内容。
语法
表达式 。GetChunk (Offset、 Bytes)
表达式 一个表示 Field2 对象的变量。
参数
名称 |
必需/可选 |
数据类型 |
说明 |
|---|---|---|---|
Offset |
必需 |
Long |
开始复制前要跳过的字节数。 |
字节 |
必需 |
Long |
要返回的字节数。 |
返回值
Variant
备注
将 GetChunk 返回的字节指定给变量。 使用 GetChunk 每次返回总数据值的一部分。 可以使用 AppendChunk 方法重新组装片段。
如果 offset 为 0, 则 GetChunk 将从字段的第一个字节开始复制。
如果数字大于字段中的字节数, 则 GetChunk 返回字段中剩余字节的实际数目。
注意
[!注释] 对文本使用 Memo 字段,只能在 Long Binary 字段中放置二进制数据。 否则会导致不合需要的结果。
示例
以下示例使用 AppendChunk 和 GetChunk 方法,用来自其他记录的数据,以每次 32K 的形式填充 OLE 对象字段。 在实际的应用程序中,用户可以使用与此类似的过程,将雇员记录(包括雇员的照片)从一个表复制到另一个表。 在以下示例中,只是将记录复制回到同一个表。 请注意,所有块操作将在单个 AddNew-Update 序列中发生。
Sub AppendChunkX()
Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Dim rstEmployees2 As Recordset
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
' Open two recordsets from the Employees table.
Set rstEmployees = _
dbsNorthwind.OpenRecordset("Employees", _
dbOpenDynaset)
Set rstEmployees2 = rstEmployees.Clone
' Add a new record to the first Recordset and copy the
' data from a record in the second Recordset.
With rstEmployees
.AddNew
!FirstName = rstEmployees2!FirstName
!LastName = rstEmployees2!LastName
CopyLargeField rstEmployees2!Photo, !Photo
.Update
' Delete new record because this is a demonstration.
.Bookmark = .LastModified
.Delete
.Close
End With
rstEmployees2.Close
dbsNorthwind.Close
End Sub
Function CopyLargeField(fldSource As Field2, _
fldDestination As Field2)
' Set size of chunk in bytes.
Const conChunkSize = 32768
Dim lngOffset As Long
Dim lngTotalSize As Long
Dim strChunk As String
' 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
strChunk = fldSource.GetChunk(lngOffset, conChunkSize)
fldDestination.AppendChunk strChunk
lngOffset = lngOffset + conChunkSize
Loop
End Function