Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Linking an image in a form

1 view
Skip to first unread message

Access Help

unread,
Jul 16, 2007, 11:28:00 PM7/16/07
to
Hi all,
I am trying to link a image from a table. So when I call up the record I
want the image from that record to display in the form. Can anyone please
help?
Thanks

John Mishefske

unread,
Jul 17, 2007, 12:59:34 AM7/17/07
to

I believe the most accepted method is to store the drive, path and
filename of the image into a text field in a table instead of actually
saving the binary data that makes up the image.

Storing binary data in Access tends to lead to "bloat" - increase in
file size of the Access app requiring the periodic use of the "Compact"
feature.

Your form would have a text control that is "bound" to the referenced
text field. In your form's OnCurrent event (which fires each time the
form navigates to a record) you would get the value of the bound textbox
control, test that the file exists and then load it into the appropriate
Image control.

If the file isn't found then set the Image's x property to "(none)" so
that no picture is displayed. Something like:

Private Sub Form_Current()
On Error GoTo errHandler

Dim sPath As String

' use the same folder the database is in
sPath = CurrentProject.Path & "\"

' if file exists
If ((Len(Me!txtParentPicture & vbNullString) > 0) And _
(Len(Dir(sPath & Me.txtParentPicture)) > 0)) Then

Me!imgParentPicture.Picture = sPath & Me!txtParentPicture
Else
' otherwise display nothing
Me!imgParentPicture.Picture = "(none)"
End If

Exit Sub
<error handling>
End Sub


--
'--------------------------
' John Mishefske
' UtterAccess Editor
' 2007 Microsoft Access MVP
'--------------------------

Larry Linson

unread,
Jul 18, 2007, 12:23:42 AM7/18/07
to
"Access Help" <Acces...@discussions.microsoft.com> wrote

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.

And, Stephen has an ActiveX control available that works in cases where the
graphics filters are not available -- and works better, I've heard, than the
OLE Object and OLE Controls.

Please note that there are other approaches, e.g.,
Application.FollowHyperlink, but those, like OLE and Bound OLE Frames (which
from the symptoms you describe, are what you were / are using) still leave
you "at the mercy of the imaging software registered for the filetype").

Finally, Access 2007 has enhancements that, reputedly, eliminate the
database bloat long associated with OLE Objects and Bound OLE Frames. But,
it still leaves you relying on the software registered for the image type,
which may not be as "cooperative" as we'd like in creating our display. It
also has the capability of having a variable number of Attachments to a
Record, which may be helpful. But, as I have not done much with it yet, I
certainly wouldn't suggest you rush out and replace an earlier version --
not until the first Service Pack, at least.

Larry Linson
Microsoft Access MVP


0 new messages