Go Premium for a chance to win a PS4. Enter to Win


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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

916 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