Reputation: 93
Why doesn't my image get inserted? Here is my code.
Sub SaveToDBs(strImagePath As String, fname As String)
rs.Close
rs.Open "Sheet1", conn, adOpenDynamic, adLockBatchOptimistic, adCmdTable
Dim bytBLOB() As Byte
MsgBox strImagePath
Dim intNum As Integer
With rs
intNum = FreeFile
Open strImagePath For Binary As #intNum
ReDim bytBLOB(FileLen(strImagePath))
'Read data and close file
Get #intNum, , bytBLOB
Close #1
.Fields(fname).AppendChunk bytBLOB
.Update
End With
MsgBox "done"
End Sub
I got "done" msgbox but image not inserted !!!!
Upvotes: 1
Views: 4434
Reputation: 304
I normally use ADODB.Stream for this sort of thing - I find it easier to understand than the chunking methods.
Sub SaveToDBs(strImagePath As String, fname As String)
rs.Close
rs.Open "Sheet1", conn, adOpenDynamic, adLockBatchOptimistic, adCmdTable
MsgBox strImagePath
Dim intNum As Integer
Dim myStream as ADODB.Stream
With rs
.AddNew
Set myStream = new ADODB.Stream
myStream.Type = adTypeBinary
myStream.LoadFromFile(strImagePath)
.Fields(fname) = myStream.Read
.Update
Set myStream = Nothing
End With
MsgBox "done"
End Sub
ADODB.Stream was added from ADO version 2.5:
ADO Version History
ADO Stream Documentation
Upvotes: 3
Reputation: 11991
You have to persist bitmaps in structured storage for the MS Access binding to work as expected.
Take a look at Edanmo's Load and save pictures to byte arrays. sample for a way to serialize in a compatible way. Then you could use simple assignment to update your recordset field if it's a client side one.
Upvotes: 1