GetChunk and FieldSize Methods Example

This example uses GetChunk with a data control to save the contents of a field to a separate file.  You would call this procedure with the path and name of the file where you want to save the contents of the field.  This procedure works for either text or binary fields.

Sub GetBigFile (FName As String)
  Dim NumChunks As Long, TotalSize As Long
  Dim RemChunk As Integer, CurSize As Integer
  Dim I As Integer, FNum As Integer, CurChunk As String
  ChunkSize = 2000                            ' Set size of chunk.
  ' Get field size.
  TotalSize = Data1.RecordSet.Fields("Comments").FieldSize()
  NumChunks = TotalSize \ ChunkSize           ' Set number of chunks.
  ' Set number of remaining bytes.
  RemChunk = TotalSize Mod ChunkSize
  ' Set starting size of chunk.
  CurSize = ChunkSize
  FNum = FreeFile                             ' Get free file number.
  Open FName For Binary As #FNum              ' Open the file.
  For I = 0 To NumChunks
    If I = NumChunks Then CurSize = RemChunk
    CurChunk = Data1.RecordSet.Fields("Comments").GetChunk(I * ChunkSize, CurSize)
    Put #FNum, , CurChunk                     ' Write chunk to file.
  Next I
  Close FNum
End Sub