Loading Field of type 'OLE Object' in Picture control

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?

Tony....
LVL 1
CGIAMETTAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Benjamin_LukCommented:
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")
rs.MoveFirst
Dim obj As New ADODB.Stream
With obj
.Type = adTypeBinary
.Open
.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
.Open
.LoadFromFile "N:\Ben.JPG"
rs.AddNew
rs.Fields(0) = .Read
rs.Fields(1) = "JPG"
rs.Update
End With

Set obj = Nothing
Set rs = Nothing
End Function


Best Regards

Ben
0
CGIAMETTAAuthor Commented:
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.

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

Here's a few links for you
http://support.microsoft.com/default.aspx?scid=kb;en-us;285820&Product=acc2003

one from Candace-Tripp with a small sample app
http://www.candace-tripp.com/_pages/access_downloads.asp#18

Here's a really good sample - (DownloadFiles/PictureBoxA2K)
http://www.lebans.com/toc.htm


Cheers
Michael
0
Emanon_ConsultingCommented:
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.
http://support.microsoft.com/default.aspx?scid=kb;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).
http://www26.brinkster.com/alzowze/blobs.asp

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
http://www.mvps.org/access/api/api0001.htm


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.

Cheers
Michael
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

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.