Solved

Save and Load picture with Access database !

Posted on 2001-06-11
4
311 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

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

Suggested Solutions

Title # Comments Views Activity
how to open Waze.com/livemap from address saved in DB? 26 177
VBA: Add rows to listbox based on criteria 7 73
How to make an ADE file by code? 11 79
Help me. 3 46
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

910 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

22 Experts available now in Live!

Get 1:1 Help Now