Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add pictures on access table

Status
Not open for further replies.

skarosi

Programmer
Jan 25, 2004
140
GR
Hi all,
I am creating a DB of movies and music records, that is then used on a VB program.I was thinking that it would b nice to have it print an image of the cover next to the search results.
i guess i can do the programming fairly easy, but what i dont know is how to save the pictures as a part of the access table.
I tried to search for it on the forums, but with no luck
any ideas?

thanks, Ilias
 
you can set the datatype of a field to be a ole object, this will allow you to store pictures...

however usually, people just store a string path for the relevant picture because storing pictures on the database would slow things down a lot...

you can still open the picture on the forms quite easily...

--------------------
Procrastinate Now!
 
yes, i was thinking that i can do something like that. get the path and get the windows to show it. might b easier as well,
cheers
 
If you really need to store in the db look into the sample Northwind db provided with Access.

________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
If you have a few images this is simple. Like everyone said, just stick it in a table as an OLEand use a bound image control. As said the Northwind example will show you how. However, it sounds to me like you will have a lot of images. Just because the image is .5 mb does not mean the data base grows by .5 mb. More likely it will grow by about 2 mb. OLE object bring along a lot of overhead relating to the application that opens them.
Here is a simple class module I built to show pictures on forms and reports that are stored in a picture directory. The form must have an image control and a control with the name of the picture (i.e. mypic.jpg).
To use the class simply load the PictureFromFile class into a class module. Then on any form or report instanitate the class, and tell it the path to the picture directory, the control that has the picture names, and the form or report. Here is how you do that:
Code:
Option Compare Database
Option Explicit
Public pffPicControl As PictureFromFile

Private Sub Form_Open(Cancel As Integer)
  Set pffPicControl = New PictureFromFile
  Set pffPicControl.PictureControl = Me.imgImageControl
  pffPicControl.PictureDirectoryName = "C:\"
  Set pffPicControl.PictureForm = Me
  Set pffPicControl.PictureNameControl = Me.Controls("strPictureName")
End Sub
That it. The pictures should now load and display.

Now here is the class module called "PictureFromFile
Code:
'This class was developed by MajP
'Feel free to use or distribute.
Option Compare Database
Option Explicit

Private mPictureNameControl As TextBox
Private mImagePath As String
Private mImageControl As Image
Private mPictureDirectoryName As String
Private WithEvents mForm As Access.Form
Private WithEvents mReport As Access.Report
Public Property Set PictureNameControl(thePictureNameControl As TextBox)
  Set mPictureNameControl = thePictureNameControl
 End Property
Public Property Set PictureControl(theControl As Image)
  Set mImageControl = theControl
End Property
Public Property Set PictureForm(theForm As Access.Form)
  On Error GoTo HandleError
  Set mForm = theForm
  mForm.OnCurrent = "[Event Procedure]"
  Exit Property
HandleError:
  MsgBox Err.Number & "  " & Err.Description
End Property
Public Property Set PictureReport(theReport As Access.Report)
  Set mReport = theReport
  mReport.OnPage = "[Event Procedure]"
  mReport.OnActivate = "[Event Procedure]"
End Property
Private Sub subLoadImage()
   Dim strImagePath
   Dim objFileSystem As Object
   'On Error GoTo PictureNotAvailable
   Set objFileSystem = CreateObject("scripting.FileSystemObject")
   strImagePath = mPictureDirectoryName & mPictureNameControl.Value
   'If files exists Set ImageFrame to the path of the image file
   If objFileSystem.FileExists(strImagePath) Then
      mImageControl.Picture = strImagePath
      mImagePath = strImagePath
   Else
     mImageControl.Picture = ""
   End If
   Exit Sub
PictureNotAvailable:
   MsgBox Err.Number & "  " & Err.Description
End Sub
Private Sub mForm_Current()
  Call subLoadImage
End Sub
Private Sub mReport_Activate()
  Call subLoadImage
End Sub
Private Sub mReport_Page()
  Call subLoadImage
End Sub
Public Property Get PictureDirectoryName() As String
  PictureDirectoryName = mPictureDirectoryName
End Property
Public Property Let PictureDirectoryName(ByVal theDirectoryName As String)
   mPictureDirectoryName = theDirectoryName
End Property

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top