Link to home
Start Free TrialLog in
Avatar of ckvkkeek
ckvkkeek

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ckvkkeek
ckvkkeek

ASKER

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
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.
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.
Correction:
What I did instead was stored each image images in a unique filename.
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.
>>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.
Fully aware.  And we will document and warn users because of these limitations.

Thanks.
ck