Question

Show a picture stored in Access on an Access form

Asked by: bthouin

Hi

I'm pulling my hair out on what I thought would be a simple problem:
- I have an Access DB with a form
- in the DB, I have a table with 2 fields: image name, image ( of type OLE object)
- I have manged, by using code found on the Internet, to store a bitmap image in my table
- but now, for the life of me, I CANNOT retrieve this image into a simple image control or an OLE unbound frame !
- first I don't know which kind of control I should use (I've read control names on the Internet which I can't find in Access and also not in the add-ins)
- second a simple control doesn't seem to do

I get only weird errors like:
- The setting for this property is too long
- The bitmap you specified is not in a device-independant bitmap (.dib) format

You'll see in the code area what kind of things I tried which resulted all in errors or compile errors.

Can someone tell me how to "read in" my OLE object out of my simple table into a standard control on an Access form ? I'm despairing, mainly because of the time lost with this "simple problem". I am using MS Access 2002 SP3.

Bernard

Public Function SetImage(logo As String)
    Dim rs As Recordset
 
    Set rs = CurrentDb.OpenRecordset("SELECT Image FROM tbLogos WHERE ImageName = '" & logo & "'", dbOpenDynaset)
    Me.OLEUnboundFrame.SourceItem = rs!Image     ' Error: setting for property too long
    Me.OLEUnboundFrame.Action = acOLEEmbed
    Me.imgBox.PictureData = rs!Image                        ' bitmap format error
    'Me.imgBox.DataSource = rs                                 ' Compile error
    'Me.imgBox.DataField = "Image"                             ' Compile error
End Function

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-03-19 at 15:31:54ID24247758
Topics

Access Forms

,

Access Coding/Macros

Participating Experts
3
Points
250
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Bitmaps, DIBs and MFC
    I need some code to allow me to create a Bitmap in memory (preferably as a CBitmap) draw on it using standard CDC stuff, then save it as a DIB. I've looked at the PAQs and there's nothing that useful... I can't get to www.codeguru.com at the moment although I'm pretty sure th...
  2. BITMAP<==>DIB
    I am very frucstrated by the bitmap structures in VC and SDK. Specifically, what are the differences between BITMAP and DIB? Can they be converted to/from each other? In addition, there is a class called CBitmap in VC to be used with BITMAP. What about DIB? Thank for any o...
  3. DIB Question...
    The following code illustrates that I have the info necessary to successfully copy a bitmap to the clipboard. if( OpenClipboard() ) { EmptyClipboard(); SetClipboardData(CF_DIB,Bmp.e_dib); CloseClipboard(); return TRUE; } How do I use this data to sav...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: boag2000Posted on 2009-03-19 at 19:48:34ID: 23936541

bthouin,

My opinion?

Drop the OLE approach.
Storing images in the DB cause enormous bloat.
Instead "Link" to the files and display them in a form.

Fully functioning sample attached.

;-)

JeffCoachman

 

by: bthouinPosted on 2009-03-20 at 03:30:59ID: 23938106

Sorry Jeff, but that's exactly what I DON'T want to do. I am developing a standard product that will be sold to a small number of clients. On the main form, I want to show the client's logo to peronalize the app a bit. I want to have that client logo in the DB so that I'm independant of the installation setup. So I don't care about the bloat. The logos are small anyway, I'm not talking about fancy 10 megapixels photos, but about small bitmaps (3-5 KBytes) :-)

So I need a way to show my already stored logo somewhere on a form... Do you have a solution for that ?

Regards
Bernard

 

by: boag2000Posted on 2009-03-20 at 07:55:11ID: 23939872

bthouin,

You can certainly create an OLE field in a table and insert/embed images into it.
If you then create a form or report from this table, the image will display.
(I know this is not what you are after, I am just mentioning it.)

But I am not sure how you would reference this stored image in a control.

Anytime you insert an image control it wants a path to an external image. I, personally, have never been able to make an Image control reference an image stored in a Table.

If you just use a standard image control you can point it to any external image.
(In order to embed/store the image in the control, DO NOT check on the option button for "Link".
Since you probably wont be adding Reports/Forms all that often, (and the images will probably be small) you can just copy and paste the image control Logo from one Report/Form to another.

JeffCoachman

 

by: bthouinPosted on 2009-03-29 at 07:31:36ID: 24012835

Hi Jeff

>>I, personally, have never been able to make an Image control reference an image stored in a Table<<

It MUST be possible, though, 'cause I found an example .mdb on the Internet which has 2 pictures stored in a table in the DB, and loads them alternatively into a command button when you click on the command button. I enclose the app for your perusal

  • ImageData.zip
    • 26 KB

    Access DB which demonstartes loading of images from DB to a control

 

by: boag2000Posted on 2009-03-30 at 02:31:54ID: 24017191

I am familiar with the sample you posted,

In that sample the images are "embedded" in the form.
Using the code, the images are converted to "BLOBS" (B)inary (L)arge (O)(B)jects.
Then stored in a table, then retrieved, and displayed into the sample form.

You stated that your images are stored as OLE Datatypes, and that you:
 "manged, by using code found on the Internet, to store a bitmap image in my table"
But you did not explictly say how you did this or what format/Datatype you converted them to.
The you went on to say:
 " Can someone tell me how to "read in" my OLE object out of my simple table "
?
So are the images now OLE objects again?

Can you clearly state what Datatype you images are currently in?


The Code in this sample (AFAICT) converts embedded images to BLOBS, not OLE images to BLOBS.
If your images are truly BLOBS, then this code should work for you.

OLE Fields were meant only to give you Access to the file.
Typically the OLE file will open in it's native application.

See here for info on converting OLE Fields to BLOBS:
http://www.access-programmers.co.uk/forums/showthread.php?t=119979

http://www.experts-exchange.com/Programming/Editors_IDEs/PowerBuilder/Q_20951167.html

(Can't be done?)
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_20431268.html

Let me know how you make out.

JeffCoachman

 

by: bthouinPosted on 2009-03-30 at 15:25:55ID: 24024099

Hi Jeff

Working on it, to make a nice demo of where the problem lies: I can effectively show the images stored in that app I sent you, I can't show my own, so the solution must have to do something with the way I stored my bitmap image in the Access DB. To do that, I defiend a table with a picture name field (text) and an image field (OLE object, the famous one). So did the guy who wrote the app I sent you. I store dthe bitmap in it like this:

That image can NOT be retrieved by:

Set rs = CurrentDb.OpenRecordset("SELECT Image FROM tbLogos WHERE ImageName = '" & logo & "'", dbOpenDynaset)
 Me.imgBox.PictureData = rs!Image

The 2nd statement gives me the famous error about the wrong type of bitmap.

However, the very same 2 statements work perfectly well on the table in the app I sent you, although that table at first sight looks exactly the same.

So the difference must be in the way the images were stored in that app. Unfortunatelym, that's exactly the thing which is missing in that app, it doesn't say how the images were stored.

My storage method is found in several internet articles about storing images in Access, but there still must be something "wrong" with it. But what ???

Let's hope you can tell me what...:-)

Cheers
Bernard

Public Function StoreImage(fileName As String)
    Dim fileNameShort As String
    Dim FileBinary As String
    Const blockSize = 32768
    Dim NumBlocks As Integer
    Dim i As Integer
    Dim LeftOver As Long
    Dim FileLength As Long
    Dim rs As Recordset
    Dim sArr As Variant
    
    sArr = Split(fileName, "\")
    fileNameShort = sArr(UBound(sArr))
    Set rs = CurrentDb.OpenRecordset("tbLogos", dbOpenDynaset)
    rs.AddNew
        rs!ImageName = fileNameShort
    rs.Update
    Set rs = CurrentDb.OpenRecordset("SELECT Image FROM tbLogos WHERE ImageName = '" & fileNameShort & "'", dbOpenDynaset)
    rs.Edit
        Open fileName For Binary Access Read As #1
        FileLength = LOF(1)
        NumBlocks = FileLength \ blockSize
        LeftOver = FileLength Mod blockSize
        FileBinary = String$(LeftOver, 32)
        For i = 1 To NumBlocks
            Get #1, , FileBinary
            rs("Image").AppendChunk FileBinary
        Next i
    rs.Update
    Close #1
    rs.Close
    Set rs = Nothing
    
End Function
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:

Select allOpen in new window

 

by: boag2000Posted on 2009-03-30 at 19:45:00ID: 24025345

Again, from what I remember about that file, the images are Embedded in the Access program.
Notice how they represent Access "Icons".
The are not actually stored in the table.

The code is what inserts them into the table.

Notice the the table only has two images in it, while the form has about six.

I have tried to contact the developer who created that file, he is a member here.

Jeff

JeffCoachman

 

by: LPurvisPosted on 2009-03-31 at 01:01:39ID: 24026619

There are ultimately (at least) three formats of image storage at play here.

The much maligned "OLE field" is a required data type.
OLE Objects however are an Access concept where binary objects are inserted via Access functionality with wrapping required to allow rendering (convenient display) within the Access UI.  This convenience is what comes at the cost of bloating in DB size.
One main advantage of the OLE Object (prior to Access 2007) is that it can be used in continuous forms to display distinct, bound objects (images).

BLOBs are different in that they are inserted "by hand" in that we do it ourselves in code - stuffing the raw binary data into the field.  But it's still in the "OLE Field" data type.  (It is nothing more than a Long Binary data type - the type of which is supported in any any reasonable RDBMS).  That we often see "OLE Objects" in there gives them a bad rep.
BLOB data (images) in OLE Fields need to be extracted before they can be used as such again.  This takes a definite overhead and lag time.  (See the BLOB demo in the examples page link in my profile).

The example in this thread is a third image type.
Access image controls display images from disk (and can be linked or embedded data).
The binary data of that image again contains a small amount of Access formatting data (nothing like the OLE Objects - a tiny amount).  That image data in the control is exposed (and assignable) through the Image control's PictureData property.
We can store that data aquired from that property (stashed in an OLE - Long Binary - field or even a Memo field is capable of filling the role).  And then re-assign it to other controls at will.
Why?
Efficient storage (the data's the same size as the file from which it came).  Re-usable images (the single stored image data can be used in multiple forms and reports without the bloat of embedding in each UI object or the time lag in loading from disk - as loading the PictureData property is much quicker than a disk read of a file).

However the Access formatted images (OLE Objects and PictureData stored data) can't be readily used as BLOB data to create usable files.  If you have stored OLE Objecs then Stephen Lebans has provided a mass extract to disk utility.

The example from this thread stores PictureData property data and re-sets it.
Data stored by other means needs to be assigned by other means.
Your StoreImage example is inserting BLOB data.  To display that in a native Access image control then you need to extract the image to file again and set an Image control's Picture property to that path.


The final thing to mention is Access 2007's Attachment data type (part of the new Multi-Value field functionality) allows both efficient insertion of file data (it's compressed upon insertion) and the bound display of images (as OLE Objects can) including continuous view.
2007's Image controls also support binding to a Text data field which describes an image path.  (Which again allows different images in continuous view).  Useful and welcome functionality.

 

by: boag2000Posted on 2009-03-31 at 06:32:47ID: 24028706

Thanks for helping out here Leigh.
;-)

Jeff

 

by: boag2000Posted on 2009-03-31 at 06:34:23ID: 24028721

bthouin,

See here for other worthwhile information:
http://www.lebans.com/oletodisk.htm

Jeff

 

by: LPurvisPosted on 2009-03-31 at 06:38:05ID: 24028753

Yep - that's the util.  (Applicable to OLE Objects - which are notoriously hard to extract otherwise).

 

by: bthouinPosted on 2009-03-31 at 14:15:04ID: 24033761

So, if I understood you correctly, Leigh, I should:
- first load my bitmaps one after the other into an image control in Access. This will give them this famous "small amount of Access formatting data" which later on will make the image control accept it again as proper PictureData for the image control
- then store each of the image control content into the database using the code that I showed in my last mail, but of course not by reading a file but the PictureData instead chunk by chunk into the infamous OLE object column of my image table
- then load that data back into the image control's PictureData, using of course the image I want to appear there

Is that correct ?

@Jeff: just wanted to tell you that no, "the images are" NOT "embedded in the Access program" (the one app I sent you), they are in a table in that Access DB. To show the images the code is making a DLookUp. That's definitively getting the images from the DB :-)

@both of you: thanks a lot for your profound knowledge. I'm stunned, however, to discover that what I thought was a VERY simple problem turns out to be such an incredibly complex feast.

Thanks again. I'll keep you posted about my progress when I get time to try out. And just tell me if the above is wrong ! And you'll get the points when I've succeeded, that might take a few days...

Cheers
Bernard

 

by: LPurvisPosted on 2009-03-31 at 15:06:27ID: 24034209

You've got it yes.  Bang on.

I wouldn't worry too much about breaking down the data unless your images are rather large (which would be unusual for an application internal type image/icon).
Though you're using AppendChunk either way - you can do it all in one.
(The example in my links page uses ADO's stream and command objects to perform a similar role).

Cheers.

 

by: boag2000Posted on 2009-04-01 at 03:47:13ID: 24037687

bthouin,

"the images are" NOT "embedded in the Access program" (the one app I sent you), "

Yes, this I knew, I was referring to the sample you were using as a reference
(where there were two image entries in the table, but Image form had about 5 images on it.
The button images on the form are Embedded, then the code converted them, then stored them in the table.

But I think LPurvis explained this a lot better than me.
;-)

Sorry for the confusion.
;-)

Keep us posted on your progress

Jeff

 

by: rockiroadsPosted on 2009-04-02 at 10:47:45ID: 24052549

Sorry to hijack this but this is a msg for Mr Purvis and maybe Jeff if your freelance. Care to add your contractor thoughts here please http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_24288996.html

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...