storing photos in database

G

Guest

I have to say my heart sank when I found Access 2003 couldn't display images
(in my case jpegs) in a form-based OLE field. However, it's been a godsend
because I was getting prepared to load over 500 images by hand into my
database and this forum provided a work around, using an unbound image
control, which meant I could directly access the saved photos. In case
anyone's interested, here's the way I found to do this with the OnCurrent
event of the form (in my case, the photos were already handily named by way
of the table's ID field and were stored in a subfolder to the database's own
folder):

Private Sub Form_Current()
On Error GoTo handler
Dim myPath As String
If IsNull(ID) Then 'to stop error with new record
myPath = ""
Else
myPath = CurrentProject.Path & "\" & "Photos\" & ID & ".jpg"
End If
imgPhoto.Picture = myPath 'imgPhoto is name of image control
Exit Sub
handler:
If Err.Number = 2220 Then 'missing photo for ID
imgPhoto.Picture = ""
Else
Msg Err.Number & " " & Err.Description
End If
End Sub

If you've got missing photos, you can put a label behind the image control
saying something like "Photo Unavailable".
 
L

Larry Linson

Martin said:
I have to say my heart sank when I found
Access 2003 couldn't display images
(in my case jpegs) in a form-based OLE field.

Maybe you could clarify? What do you mean a "form-based OLE field"? There
are OLE Fields, but they exist in Tables and Queries and they cannot be
"form-based".

Do you perhaps mean either a "Bound OLE Frame" or an "Unbound OLE Frame"?
Those are Controls that you can place on a Form or Report to display OLE
Objects from OLE Fields. Either should be able to display a JPEG file,
provided you have appropriate OLE-enabled software registered for the JPG or
JFIF file type in your registry. But, you are "at the mercy" of whatever
OLE-enabled image processing software you have registered -- some will not
display a smaller copy of a larger image in an Access Control. That's why I
created the following "boilerplate" to refer to the website for an example
of that and other approaches:

The sample imaging databases at http://accdevel.tripod.com illustrate three
approaches to handling images in Access, and the download includes an
article discussing considerations in choosing an approach. Two of the
approaches do not use OLE Objects and, thus, avoid the database bloat, and
some other problems, associated with images in OLE Objects.

If you are printing the images in reports, to avoid memory leakage, you
should also see MVP Stephen Lebans' http://www.lebans.com/printfailures.htm.
PrintFailure.zip is an Access97 MDB containing a report that fails during
the Access formatting process prior to being spooled to the Printer Driver.
This MDB also contains code showing how to convert the contents of the Image
control to a Bitmap file prior to printing. This helps alleviate the "Out of
Memory" error that can popup when printing image intensive reports.

Larry Linson
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top