Adding Pictures in A Database

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

I am trying to create a database that would generate a
catelog, complete with pictures. I thought that if I
linked my photograph that my dtabase would not grow too
large, I find I am wrong. I need to be capable of placing
several hundred pictures into a database without exceeding
the database size limit of 2 GB.

Is there a hero out there with a simple solution for a non-
database expert?
 
Hi Jim

Yes, the OLE Object is useless for storing images, because of the bloat.

Consider using a Hyperlink field instead. This lets you store just the link
to whereever you stored the JPG file on your disk. Right-click to insert the
file, or use the Insert menu. For an introduction to how hyperlink fields
work, see:
http://allenbrowne.com/casu-09.html

Now you want to show the picture in your form. Add an Image control, and use
the Current event of the form to set the Picture property of the image
control.
 
Allen,

Your advise is GREATLY appreciated, thanks you. Could you
please go a step further and wlak me through the process
of getting the picture to be visiable in my report/catelog?

Thanks,

Jim
 
This is the kind of thing you could use in Form_Current.

It assumes:
- a hyperlink field named "MyPic",
- the path to the image in a text field named "txtImageFolder",
- an image control named "img1", and
- a label named "lblNoImage" that shows the text "No Image" if there is no
picture (or the link is no longer valid):


Dim bShow As Boolean
Dim strFullPath As String

With Me.img1
If Not (IsNull(Me.MyPic) Or IsNull(Me.txtImageFolder)) Then
'Check the file is still here. Can't show if it is not.
strFullPath = Me.txtImageFolder & MyPic
If FileExists(strFullPath) Then
bShow = True
If .Picture = strFullPath Then
'do nothing
Else
.Picture = strFullPath
End If
End If
End If
If .Visible <> bShow Then
.Visible = bShow
Me.lblNoImage.Visible = Not bShow
End If
End With

Public Function FileExists(varFullPath As Variant) As Boolean
On Error Resume Next
If Len(varFullPath) > 0& Then
FileExists = (Len(Dir$(varFullPath)) > 0&)
End If
End Function
 
Back
Top