When reading/writing blobs into tables there's much simpler code:
Code:
Public Sub setBLOB(RS As ADODB.Recordset, Field As String, Source As String)
'' Places file into database
'setBLOB myRecordSet, "FileField", "c:\FileToAdd.rtf"
Dim fileBytes() As Byte
Dim intFileHandle As Integer
intFileHandle = FreeFile
Open Source For Binary As intFileHandle
fileBytes = InputB(LOF(intFileHandle) - 1, intFileHandle)
RS(Field).AppendChunk fileBytes
Close intFileHandle
End Sub
Public Sub getBLOB(RS As ADODB.Recordset, Field As String, Des As String)
'' Save file to disk
'getBLOB myRecordSet, "FileField", "c:\FileToSaveto.rtf"
Dim lngFieldSize As Long
Dim fileBytes() As Byte
Dim intFileHandle As Integer
intFileHandle = FreeFile
lngFieldSize = RS(Field).ActualSize
If lngFieldSize > 0 Then
fileBytes = RS(Field).GetChunk(lngFieldSize)
Open Des For Binary As intFileHandle
Put intFileHandle, , fileBytes
Close intFileHandle
End If
End Sub
Sub TestBlob()
Dim RS As New ADODB.Recordset
RS.Open "SELECT * FROM tblBlob", CurrentProject.Connection, adOpenStatic, adLockOptimistic
RS.AddNew
setBLOB RS, "BlobFileField", filePath & "TestIn.rtf"
RS.Update
RS.Close
getBLOB RS, "BlobFileField", FilePath & "testOut.rtf"
End Sub
Comment