Solved

Save and Load picture with Access database !

Posted on 2001-06-11
4
318 Views
Last Modified: 2012-08-13
Hi there !
I am using VB to access a table from Access database, please tell me with ADO code or DataEnv ActiveX how to :

1. Load picture from access database into Picture Box control ?

2. Save picture which selected in Picture Box control into Access Database ?

Notes:     I means save itself not it's link.

Thanks so much !
0
Comment
Question by:e9608092
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
sharmon earned 200 total points
ID: 6179990
If you are using ADO 2.5 or higher, you can use the stream object.  I will give you basics, if you know enough you'll be fine, if not, just ask and we'll help you.  If you are using ADO 2.1 or lower, this will not work, you'll have to use the old method, let us know and I am sure me or someone will give you that code, but I'd recommend using ADO 2.5 or higher.


This will read a steam from the database and store it as a file...replace d:\tmp.pic with whatever suits you.

If IsNull(rs.Fields("Photo").Value) Then
    Picture1.Picture = LoadPicture()
Else
    Dim adoStream As New ADODB.Stream
    adoStream.Type = adTypeBinary
    adoStream.Open
    adoStream.Write rs.Fields("Photo").Value
    adoStream.SaveToFile "d:\tmp.pic", adSaveCreateOverWrite
    Picture1.Picture = LoadPicture("d:\tmp.pic")
    adoStream.Close
    Set adoStream = Nothing
End If

If you want to write an image to the database you can use this...if you need to save your picturebox to a file first you can, but it will save as a bitmap and it will be alot bigger than a jpg or gif, so I would recommend grabbing the jpg or gif from the file instead of writing out the bitmap to the disk.

Dim adoStream As New ADODB.Stream

adoStream.Type = adTypeBinary
adoStream.Open
adoStream.LoadFromFile "d:\4.jpg"  'replace with your file

rs.AddNew
rs.Fields("Photo").Value = adoStream.Read
rs.Update

adoStream.Close
Set adoStream = Nothing
0
 
LVL 6

Expert Comment

by:sharmon
ID: 6179995
Also, if you don't already know, make sure that the field type for the photo column is OLE Object, in the example I assumed rs was the name of your recordset and that Photo was the name of the column in the recordset.  Since you seem to already know about ADO other than this, I didn't figure you'd need the whole thing explained from start to finish.  If so, just ask.
0
 
LVL 6

Expert Comment

by:simonbennett
ID: 6180245
Hi

My 2p

I have never used ado streaming, but it sounds similar to binary reads and writes. IMHO the only fast way to do this is to store the *path and filename* only in the database, and when you need to display it use the picture1.picture = loadpicture(<path and filename>).

The main reason for this is that your access db will increase in size very quickly, and the bigger it gets, the more likely it is to corrupt!

HTH and good luck

Simon
0
 

Author Comment

by:e9608092
ID: 6180552
Hello sharmon, Simon, Thank you, now I can continue my work with your instructions.


0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 40
MsgBox 4 68
Error with a code discussed on this page 5 30
VBA: Insert New column with specific format type 12 38
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

839 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