>

AppendChunk Method

Applies To

Field Object.

Description

Appends data from a string expression to a Memo or OLE Object Field object in the Fields collection of a Recordset object.

Syntax

recordset ! field.AppendChunk source

The AppendChunk method syntax has these parts.

Part

Description

recordset

A variable of an object data type that refers to the Recordset object containing the Fields collection.

field

The name of a Field object whose Type property is set to dbMemo (Memo), dbLongBinary (OLE Object), or the equivalent.

source

A string expression or variable containing the data you want to append to the Field object specified by field.


Remarks

You can use the AppendChunk and GetChunk methods to access subsets of data in a Memo and OLE Object field.

You can also use these methods to conserve string space when you work with Memo and OLE Object fields. Certain operations (copying, for example) involve temporary strings. If string space is limited, you may need to work with chunks of a field instead of the entire field.

If there is no current record when you use AppendChunk, an error occurs.

Note

The initial AppendChunk (after the first Edit method), even if the record already contains data, will simply place the data in the field as the only data. Subsequent AppendChunk calls within a single Edit session will then add to the data.

See Also

FieldSize Method, GetChunk Method, Type Property.

Example

This example uses the GetChunk method to return consecutive 16K chunks of the Notes field in the Employees table of the database Northwind.mdb. It uses FieldSize to determine how many chunks it needs to copy and then copies the chunks to the string array NoteArray() where they can be changed. It then uses AppendChunk to copy NoteArray() back to Notes.


' This line should be in Declarations section.
Option Base 1

Sub GetNotes
    Const ChunkSize = 16384    ' Set size of chunk.
    Dim intChunks As Integer, lngTotalSize As Long, intX As Integer
    Dim dbsNorthwind As Database, rstEmployees As Recordset
    Set dbsNorthwind = _
DBEngine.Workspaces(0).OpenDatabase("Northwind.mdb") ' Open table. Set rstEmployees = dbsNorthwind.OpenRecordset("Employees") ' Get field size. lngTotalSize = rstEmployees![Notes].FieldSize() ' How many chunks? intChunks = lngTotalSize\ChunkSize - (lngTotalSize Mod ChunkSize _
<> 0) ReDim NoteArray(intChunks) As String * ChunkSize ' Get current Notes field. For intX = 1 To intChunks NoteArray(intX) = rstEmployees![Notes].GetChunk((intX - 1) * _ ChunkSize, ChunkSize) Next intX ... ' Make changes. rstEmployees.Edit ' Enable editing. rstEmployees!Notes = "" ' Initialize Notes field. For intX = 1 To intChunks ' Replace with edited Notes. rstEmployees![Notes].AppendChunk NoteArray(intX) Next intX rstEmployees.Update ' Save changes. rstEmployees.Close dbsNorthwind.Close ' Close database. End Sub
Example (Microsoft Access)

The following example appends data to a Notes field in an Employees table. The Notes field is Memo data type. The procedure then returns the contents of the field using the GetChunk method, adds to the data, and appends the altered data back to the Notes field using the AppendChunk method.


Sub AddToMemo()
    Dim dbs As Database, rst As Recordset
    Dim fldNotes As Field, fldFirstName As Field
    Dim lngSize As Long, strChunk As String


    ' Return Database variable pointing to current database.
    Set dbs = CurrentDb
    ' Create table-type Recordset object.
    Set rst = dbs.OpenRecordset("Employees")
    Set fldNotes = rst.Fields!Notes
    Set fldFirstName = rst.Fields!FirstName
    rst.MoveLast                ' Populate Recordset object.
    rst.MoveFirst            ' Move to first record.
    Do Until rst.EOF            
        ' Determine size of field in current record.
        lngSize = fldNotes.FieldSize
        If lngSize = 0 Then
            MsgBox "No text in " & fldNotes.Name & " field!"
            Exit Do
        Else
            ' Return contents of Notes field.
            strChunk = fldNotes.GetChunk(0, lngSize)
            ' Alter data.
            strChunk = strChunk & "  " & fldFirstName.Value & _
                " is a terrific employee!"
            With rst
                .Edit                ' Enable editing.
                .[Notes] = ""            ' Initialize field.
                .[Notes].AppendChunk strChunk    ' Append altered data.
                .Update            ' Save changes.
                .MoveNext            ' Move to next record.
            End With
        End If
    Loop
End Sub