>
| 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. |
' 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