How to add image to Access DB in C++ (not as Long Binary)

I find all kinds of examples to add an image to a database as a long binary, but I want to add it to the database so when the user opens up their access form the image displays correctly.

I have searched for days, and can't find a solution.

Thanks for the help.
LVL 1
ckvkkeekAsked:
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.

AxterCommented:
>>so when the user opens up their access form the image displays correctly.
To do this, you have to add the object as an embedded OLE object to the Access database.

That means before writing the raw image data, you need to write embedded OLE header and associated data.

See following CodeGuru link:
http://www.codeguru.com/Cpp/data/mfc_database/microsoftaccess/article.php/c1123/
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
ckvkkeekAuthor Commented:
I think thats it!

Let me take a look at this on Monday and if it works (and I am assuming it will), you will get yourself a fat 500 points!

ck
0
ckvkkeekAuthor Commented:
That did it.  I just added an image and it showed up as a "PhotoShop" image.  This was much harder than I ever thought it would be.  The sample given on that page isn't very good, but if you can put it all together it does work.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

AxterCommented:
I recently had a similar requirement for adding images to a MS Access database, however, it slow things down so much, I had to giveup the idea.

What I did instead was stored all the images in a unique filename.  And then I added a field in the record that had the name of the file.

I was still able to view the image in my form by adding the following code:

Private Sub Form_Current()
Dim strMyString As String

strMyString = Replace(CurrentDb.Name, Dir(CurrentDb.Name), Me![Signature])
Me![SignerImage].Picture = strMyString

End Sub

In above code Me![Signature] is the field that has the filename only (or a filename and a subdirectory)

The code creates a full path by using CurrentDb.Name to determine the *.MDB file location and adding that to the value of Me![Signature] field.

Then it sets the IMAGE control field via Me![SignerImage].Picture (where SignerImage is the name of the Image control field).

This runs much faster, and the image can be any recognised MS Access image (bmp, gif, PNG, etc....)

Thanks for the points and the A grade.
0
AxterCommented:
Correction:
What I did instead was stored each image images in a unique filename.
0
ckvkkeekAuthor Commented:
Well I will use this other info as well.

I am adding a feature to my companies Scanning SDK, and I am going to offer them the ability to store images in an Access database.  I plan on giving them 3 options:
1. Store as an image that will display (my original question).
2. Store as a long binary, and provide them with code to decipher this out to a viewable image.
3. Store as a link and provide them with the code to add the image to their form (your second answer).

I am sure you are aware of the drawbacks to each, so I want to let the user choose.
0
AxterCommented:
>>I am sure you are aware of the drawbacks to each, so I want to let the user choose.

FYI:
MS Access has a 2-Gigabyte file size limit.  Actually I think this limit is associated more with the OS file size limit.

I'm not sure how many images you plan to store, or what are the size of the images, but this is something else to consider.

With my requirement, we have 250,000 records and each image is 110KB.
If I had tried to store the images in the Database, it would have taken 27-Gigabyte, which is way pass the file size limit.

If you only have about 10,000 records or less, and the images are less then 110KB, then you shouldn't have a problem.
Otherwise, you should calculate predicted record maximum with the size of the average image, to make sure you don't come close to reaching the max file size.

If you store the OLE object instead of raw image, you also have to account for additional space for OLE header data.
0
ckvkkeekAuthor Commented:
Fully aware.  And we will document and warn users because of these limitations.

Thanks.
ck
0
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
C++

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.