Solved

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

Posted on 2002-03-11
5
154 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:mnasman
Comment Utility
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
Comment Utility
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
Comment Utility

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:
mnasman earned 120 total points
Comment Utility
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
Comment Utility
The sample code works fine for me

Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now