• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

store picture in ole (blob) data type filed in msaccess

i want to store a picture file (.jpg) in msacess databse.
how to do it with adodc or adodb.recordet.

in msacess i've taken a field as a ole object.

on form i have a picturebox.
i can open a file in picture box. how to store it in database.

Why ole field ?

because i want to drag this picture in crystal report.
there again i can show only .BMP files and no .jpg

1 Solution
Try this...

Sub cmdSave_Click()
    SaveBinaryFile "C:\YourPicture.jpg" , adoRS.Fields("Picture")
End Sub

Sub SaveBinaryFile(sFileName, Field As ADODB.Field)
    Dim lFileLength As Long
    Dim lBlocks As Long
    Dim lRemainder As Long
    Dim lCurrBlock As Long
    Dim aData() As Byte
    Dim FileNumber As Long
    Dim mvarBlockSize As Long
    FileNumber = FreeFile
    Open sFileName For Binary As #FileNumber
    lFileLength = LOF(FileNumber)
    mvarBlockSize = 1000
    'check that \we have somthing in the file
    If lFileLength > 0 Then
        'start the chunk culculations
        lBlocks = Int(lFileLength / mvarBlockSize)
        lRemainder = lFileLength Mod mvarBlockSize
        'add the first chunk
        If lRemainder > 0 Then
            ReDim aData(lRemainder - 1)
            Get #FileNumber, , aData()
            '.Fields("IDropFiles").AppendChunk aData()
            Field.AppendChunk aData()
        End If
        'add the remaining chunks
        For lCurrBlock = 1 To lBlocks
            ReDim aData(mvarBlockSize - 1)
            Get #FileNumber, , aData()
            Field.AppendChunk aData()
        Next lCurrBlock
        Close FileNumber
    End If
End Sub
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
Moderator, my recommended disposition is:

    Accept BWarmuskerken's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now