AppendChunk, GetChunk Methods Example
The following example appends data to the Notes field for each record in an Employees table. The data type of the Notes field is Memo. The procedure returns the contents of the field by using the GetChunk method, adds to the data, and appends the altered data back to the Notes field by using the AppendChunk method.
Sub AddToMemo()
Dim cnn As ADODB.Connection, rst As New ADODB.Recordset
Dim fldFirstName As ADODB.Field
Dim fldLastName As ADODB.Field
Dim fldNotes As ADODB.Field
Dim lngSize As Long, strChunk As String
Set cnn = CurrentProject.Connection
rst.Open "Employees", cnn, adOpenKeyset, adLockOptimistic
With rst
Set fldNotes = !Notes
Set fldFirstName = !FirstName
Set fldLastName = !LastName
Do Until .EOF
If IsNull(fldNotes.Value) Then
strChunk = fldFirstName & " " & fldLastName & " is an excellent employee."
!Notes = strChunk
.MoveNext
Else
lngSize = Len(fldNotes)
strChunk = fldNotes.GetChunk(lngSize)
strChunk = strChunk & " " & fldFirstName & " " & fldLastName & " is and excellent Employee."
!Notes = " "
!Notes.AppendChunk strChunk
.MoveNext
End If
Loop
End With
rst.Close
cnn.Close
End Sub