Field.GetChunk メソッド (DAO)

適用先: Access 2013、Office 2013

Recordset オブジェクトの Fields コレクション内の Memo オブジェクトまたは Long BinaryField オブジェクトの内容のすべてまたは一部を返します。

構文

式 。GetChunk(Offset, Bytes)

式Field オブジェクトを表す変数です。

パラメーター

名前

必須かどうか

データ型

説明

Offset

必須

Long

コピーを開始する前にスキップするバイト数。

バイト

必須

Long

取得するバイト数。

戻り値

バリアント型

注釈

GetChunk から返されたバイト数は変数に代入されます。 GetChunk を使用して、データの値全体の一部を 1 つずつ取得します。 分割された値を集めて元の値に戻すには、 AppendChunk メソッドを使用します。

offset が 0 の場合、 GetChunk はフィールドの最初のバイトからのコピーを開始します。

numbytes がフィールド内のバイト数を超える場合、 GetChunk はフィールド内の残りの実際のバイト数を返します。

注:

[!メモ] 文字列の場合はメモ型 ( Memo) のフィールドを使用し、ロング バイナリ型 ( Long Binary) のフィールドにはバイナリ データのみ格納してください。 この逆を行うと、予期しない結果を招きます。

例

次の使用例では、 AppendChunk メソッドと GetChunk メソッドを使用して、別のレコードからのデータを一度に 32K ずつ読み込んで OLE オブジェクトのフィールドに設定します。 実際のアプリケーションでは、たとえば、社員レコード (社員の写真を含む) をあるテーブルから別のテーブルにコピーするときに、このようなプロシージャを使用します。 この使用例では、単にレコードを同じテーブルにコピーしています。 すべてのブロック操作は、1 つの 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 Field, _ 
     fldDestination As Field) 
     
     ' 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