Loading Field of type 'OLE Object' in Picture control

Posted on 2004-10-21
Last Modified: 2010-08-05
I have a database of 100 pictures. I want to build my own custom picture browser, to do this I need to retrieve an OLE Object picture from the database and put it into a unbound picture control.  How can I do this?

Question by:CGIAMETTA
    LVL 8

    Assisted Solution

    You can use ADO.Stream method,

    But you must also need to use ADO.Stream to save the picture data to your OLE field. Also, you need to add one field to save the type of picture (such as JPG,BMP,GIF) ...

    When you load the picture you need to use ADO.Stream to save the file to local drive and then link the picture to your picture object.

    Following is sample of using ADO.Stream:

    Dim obj As ADODB.Stream

    '//Output Picture
    Function OutPic()
    Dim rs As Recordset, I As Integer, ret
    Set rs = CurrentDb.OpenRecordset("Select * from myTable")
    Dim obj As New ADODB.Stream
    With obj
    .Type = adTypeBinary
    .Write rs.Fields("Picture")
    .SaveToFile "N:\Ben" & rs.Fields("Pic_Name") , adSaveCreateOverWrite
    End With
    ' here you can code to display the picture
    Kill  "N:\Ben" & rs.Fields("Pic_Name")
    Set obj = Nothing
    Set rs = Nothing
    End Function

    '//Save picture
    Function InPic()
    Dim rs As Recordset, I As Integer, ret
    Set rs = CurrentDb.OpenRecordset("Select * from myTable")
    Dim obj As New ADODB.Stream
    With obj
    .Type = adTypeBinary
    .LoadFromFile "N:\Ben.JPG"
    rs.Fields(0) = .Read
    rs.Fields(1) = "JPG"
    End With

    Set obj = Nothing
    Set rs = Nothing
    End Function

    Best Regards

    LVL 1

    Author Comment

    Before posting this quesiton, I found all kinds of solutions the same as yours.  I need a solutions that won't take the time or overhead writing to a file and reading the file to the picture control.  It does'nt even make sense to do that, surely there is a way to read it from the database ole object right into a picture control or into a variable then to a picture control.  I'll use this solution if I have to, but I am hoping to get code for what I am asking for.

    LVL 5

    Expert Comment

    Is this an Access front end and back end?
    If so here are a couple of links...

    Here's a few links for you;en-us;285820&Product=acc2003

    one from Candace-Tripp with a small sample app

    Here's a really good sample - (DownloadFiles/PictureBoxA2K)

    LVL 5

    Accepted Solution

    Here are a couple more links for you

    Here's a link to a MS Article that covers the Bloating effect of storing images and how to store the file path to the image instead.;en-us;285820&Product=acc2003

    And here is a link to Alan Warrens web site that gives another alternative.  Alan prefers to use Binary Long Objects (Blob’s).

    I believe Alan's appraoch is more suitable for larger applications as it will store the images in the Back End of your app as "BLOB's".
    His approach would make managing the application easier in the long run.  Also you can relocate your app and not loose all the links which could be devastating in a large app on a server.

    Here's another useful link for you from 'The Access Web' site...
    API: Call the standard Windows File Open/Save dialog box

    That's it for now...
    I don't know for sure if I am on track with what you are doing in your app.  If I am, then the infor I provided should be useful.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

     Java Android Coding Bundle

    Whether you're an Apple user or Android addict, learning to code for the Android platform is an extremely valuable, in-demand skill. It all starts with Java, the language behind the apps and games that make Android the top platform it is today.

    The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
    Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now