Solved

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

Posted on 2002-03-11
5
158 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

729 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