AppendChunk Method Example

This example uses AppendChunk with a data control to save the contents of a separate file into a field.  You would call this procedure with the path and name of the file you want to put into your database.  This procedure works for either Memo or Long Binary fields.

Sub PasteBigFile (FName As String)
  Dim TotalSize As Long, CurChunk As String
  Dim I As Integer, FNum As Integer, ChunkSize As Integer
  ChunkSize = 12000                        ' Set size of chunk.
  Data1.RecordSet.Edit                     ' Enter Edit mode.
  Data1.RecordSet.Fields("Comments") = ""  ' Clear Comments field.
  FNum = FreeFile                          ' Get free file number.
  Open FName For Binary As #FNum           ' Open the file.
  TotalSize = LOF(FNum)
  Do While Not EOF(FNum)
    If TotalSize - Seek(FNum) < ChunkSize Then
      ChunkSize = TotalSize - Seek(FNum) + 10
    End If
    CurChunk = String$(ChunkSize + 1, 32)
    Get #FNum, , CurChunk                  ' Read chunk from file.
    If InStr(CurChunk, Chr$(0)) > 0 Then
      CurChunk = Left$(CurChunk, InStr(CurChunk, Chr$(0)) - 1)
    End If
  ' Append chunk to Comments field.
    Data1.RecordSet.Fields("Comments").AppendChunk (CurChunk)
  Loop
  Data1.RecordSet.Update                   ' Save the record.
  Close FNum                               ' Close the file.
End Sub