Solved

Cant store images in access table

Posted on 2004-08-20
3
259 Views
Last Modified: 2011-10-03
In MS-Access 2000 i have a  table with a field image of data type OLE Object. Now when i try to add some value (Picture) in this field by :
While entring data right click on this filed -->opens a small floating window --> select Insert  Object --> it opens a Insert Object Dialog Box with two radio buttons (Create new and Create from file). --> select Create From file and the click at browse button and after selecting  the directory and file (.bmp or .jpg) from Browse box. now when i press ok in the "Insert Obect" dialog box it displays "Package" in the image field in the table.
Whereas i think it should display "Bitmap Image" here. Am i Right ? and if yes, then What is the problem.
0
Comment
Question by:astudent
  • 3
3 Comments
 
LVL 7

Expert Comment

by:Enlade
ID: 11851174

Yes, you store them as a Blob (or really vbLongBinary).  So create a DB field like this:

  Set Fld(2) = NewTBL.CreateField("Pic", dbLongBinary)

Then you save the data into the field like this:

  tempRcSet("Pic").AppendChunk Pic

And you can get the data from the field like this:

  ReDim Pic(0 To (nBytesPic - 1)) As Byte
  Pic = tempRcSet("Pic").GetChunk(0, nBytesPic)

Note that you will need to change the field number and to change fill Pic and nBytesPic appropriately.  You will also need to store nBytesPic in the DB as well (its just easier).  Then you can use that to tell you if a picture is stored or empty (if it is 0 or > 0).

Your next question is how you get the picture into the byte array.  Let me get that for you....
0
 
LVL 7

Expert Comment

by:Enlade
ID: 11851209

Yea, that is the problem.  How do you get the picture into the byte array.  I use a control that I purchased that allows me to save a picture into a byte array, but you probably don't have that control.  If I remember correctly I bought that control specificly to do this because I think I read that most people suggested saveing the JPG to a temporary file and then loading the file into a byte array before you save it into the database (as discribed above).  Let me see if I can confirm that for you.

Mind you if you want to do it the simple way and you don't mind buying a control you could get this one:

http://www.phototrue.net/

Its not a bad price.  Still, let me see if I can find out how to get the picture into a byte array.


0
 
LVL 7

Accepted Solution

by:
Enlade earned 50 total points
ID: 11851224

Yea, Microsoft suggests that you write a function to save and load Blobs to files and then when you load them you load them back into a byte array that you can GetChunk and PutChunk to the dbLongBinary field in your DB.  I can give you the link to Microsoft, but here is a link on EE that gives you more detail.

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Databases/Q_10208746.html?query=Saving+Pictures+into+Access&clearTAFilter=true

Now, I hated that solution.  So, I just went out and bought PhotoTrue and it not only gave me some minor graphic manipulation functions, it also allowed me to print an image directly into a byte array (thus avoiding that whole file processing mumbo jumbo).
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

829 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