Loading Field of type 'OLE Object' in Picture control

Posted on 2004-10-21
Medium Priority
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
  • 2

Assisted Solution

Benjamin_Luk earned 1200 total points
ID: 12377571
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


Author Comment

ID: 12385608
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.


Expert Comment

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

Here's a few links for you

one from Candace-Tripp with a small sample app

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


Accepted Solution

Emanon_Consulting earned 800 total points
ID: 12385737
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.

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.


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

When we develop an application in Ms Access 2016 we should also try to protect the queries, macros and table links. I know I may not have a permanent solution but for novice users, they will not manage to break your application. Below is the detail …
What to do if a split doesn't fit? Or a bunch of invoice lines must be rounded while the sum must match a total? It takes a little, but - when done - it is extremely easy to implement.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…

621 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