Vb 6.0 Insert image bitmap into ms access database

Why is my image not 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 a "done" msgbox, but the image is not inserted !!!!

+1
source share
2 answers

I usually use ADODB.Stream for this kind of thing - it's easier for me to understand than 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 2.5:
ADO Version History ADO
Stream Documentation

+3
source

You need to save the bitmaps in a structured storage to bind MS Access to work as expected.

Edanmo . . , , .

+1

All Articles