Solved

Cant store images in access table

Posted on 2004-08-20
3
257 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now