Solved

Cant store images in access table

Posted on 2004-08-20
3
256 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
Comment Utility

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
Comment Utility

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
Comment Utility

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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

10 Experts available now in Live!

Get 1:1 Help Now