Solved

Save in A MS-ACCESS Database a Picture in OLE?

Posted on 2002-03-11
5
157 Views
Last Modified: 2010-05-02
Hi!

I have a Picturebox and want to save it directly into a MS-ACCESS Database (without making a data and change the relation to the picturebox). I would be in need of a save and a load function, does anybody know how this works?

Falke
0
Comment
Question by:Falke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6855953
Hello

  see this article from microsoft msdn

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvbpj01/html/gs0102.asp

and here's a sample project to do that also
http://www.freevbcode.com/ShowCode.Asp?ID=589
0
 

Author Comment

by:Falke
ID: 6857366
Hi!

Could you please post the "content" from this link here

>http://www.freevbcode.com/ShowCode.Asp?ID=589 

I can't access it :(

Falke
0
 

Expert Comment

by:deepcancer
ID: 6859723

Within The Access Database, define a field type of OLE Object to hole the picture.

The following code can be used to load and save the picture into the database.

ADO Stream - Sample Code:

Public Function SavePictureToDB(RS As ADODB.Recordset, _
  sFileName As String)

  On Error GoTo procNoPicture
  Dim oPict As StdPicture
 
  Set oPict = LoadPicture(sFileName)
 
  'Exit Function if this is NOT a picture file
  If oPict Is Nothing Then
      MsgBox "Invalid Picture File!", vbOKOnly, "Oops!"
      SavePictureToDB = False
      GoTo procExitSub
  End If
 
  RS.AddNew
 

  Set strStream = New ADODB.Stream
  strStream.Type = adTypeBinary
  strStream.Open
  strStream.LoadFromFile sFileName
  RS.Fields("***YourImageField***").Value =  strStream.Read
 
  Image1.Picture = LoadPicture(sFileName)
  SavePictureToDB = True
 
procExitSub:
  Exit Function
procNoPicture:
  SavePictureToDB = False
  GoTo procExitSub
End Function

The Appendchunk()method can be used to achievd this also, but the usage of streams is a cleaner method
of coding.


Hope this helps.
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 120 total points
ID: 6859740
Hello

  The Content of this site is a sample project http://www.freevbcode.com/ShowCode.Asp?ID=589 

here's it's link
http://www.freevbcode.com/code/image.zip

if you couldn't download it, give me your email and I will send it you
0
 

Author Comment

by:Falke
ID: 6867502
The sample code works fine for me

Thanks
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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…
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…
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…

726 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