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
Solved

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

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

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

809 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