Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2002-03-11
5
Medium Priority
?
160 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 480 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses

604 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