Simplest way to put bound picture in a report.

F

FredFred

Though I'm (usually) no dummy, the zillion posts and help files I've read on
this seem to only make it more confusing. An example probably the best way
to ask it. I've got 100 products, each with a name and photo. I want a
printout which shows the name of the product and it's photo for each product.
For example, the name of a product is Gizmo. Following previous advice I
stored the photo seperate from the table as C:\Photos\GizmoPicture.jpg. I
have a table with a "ProductName" Field, and a Text(?) "ProductPicture"
field. And for the Gizmo record, I entered C:\Photos\GizmoPicture.jpg in the
ProductPicture field. Now, I'm designing the report named "Catalog" that
is going to print the 100 product names with their pictures. An now I want
to put a box with the product picture(s) into the detail section.

1. Have I done anything wrong (above) so far?
2. You will solve my fruitless 20 man-hour quest if you could tell me
exactly how to put that picture box in there. FYI I'm a smart guy and
Access power user, but a novice on Access code type programming.

Thank you

Sincerely,

Fred
 
R

Rob Parker

Hi Fred,

Good news is you've done nothing wrong so far ;-)

And the next bit is pretty simple. Place an Image control in the detail
section of your report to display the picture. You will probably be asked
to select a picture when you create the image control; pick any image file,
and after the image control has been created remove the entry from the
Picture property of the image control. I suggest also setting the Size Mode
to Zoom; this will make the pictures resize to fit the control (while
retaining their aspect ratio). Set the name of this image control to
imgProductPicture.

You then need some simple VBA code in the Format event of the detail section
of the report to display the picture associated with the current record.
Since your ProductPicture field contain the full path/filename for each
picture, all you should need is:

If Not IsNull(Me.ProductPicture) Then
Me.imgProductPicture.Picture = Me.ProductPicture
Me.imgProductPicture.Visible = True
Else
'hide image control if no picture
Me.imgProductPicture.Visible = False
End If

To prevent Access from crashing when paging rapidly through any report
containing images, you need to modify some registry keys. The details are
available at
http://www.mvps.org/access/downloads/Set_ShowProgressDialog_To_No.reg

The easy way to incorporate these is this: Cut/paste to a text file (I used
Notepad), and save as a .reg file. Then all you need do is double-click the
file, or right-click and choose "Merge", to merge the entries into your
registry. For a 19kb file of entries, that's certainly faster than
entering them all manually ;-) Note: there are more entries here than are
actually needed to solve the problem, but it's so easy to import the lot
that it's not worth figuring out exactly which ones you need.

HTH,

Rob
 
F

FredFred

Dear Rob,

Thank you very very very much!

I'm going to have to take some bravery pills and understand the specifics of
"merge" etc. before I try those registry changes....in the meantime I just
have one record in a test table to hopefully circumvent that.

Now, my next question is probably where you think "Fred said he's a novice
on code in Access, but I didn't know he was THAT dumb on that".

I did as you said, said "Event Procedure" on "On Format" property in the
detail section and typed in what you said. And so now it looks like:

Option Compare Database

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Not IsNull(Me.ProductPicture) Then
Me.imgProductPicture.Picture = Me.ProductPicture
Me.imgProductPicture.Visible = True
Else
'hide image control if no picture
Me.imgProductPicture.Visible = False
End If

End Sub


And then, when trying to preview the report, it immediately returns the
error message: Run Time Error 2465 Microsoft Office can't find the field
'ProductPicture" referred to in your expression.

I checked field name spelling.

Can you tell what I did wrong?

Thanks

Sincerely,

Fred Turek
 
R

Rob Parker

Hi Fred,

Sorry 'bout that - I omitted one thing (guess I automatically assumed it).
You need the field ProductPicture in a (textbox) control in your report's
detail section; you can set the visible property of the textbox to No so
that it doesn't appear.

HTH,

Rob

PS. I notice, from the code you posted, that you do not have Option
Explicit at the head of your code module. If you are going to get into VBA
coding, I strongly suggest that you enable this, via the Tools - Options in
the VBA editor: check the Require Variable Declaration checkbox on the
editor tab (in fact, I suggest you check everything on that tab). Doing so
will add that line to the head of every module, and will force you to
declare all variables that you use in your code (eg. Dim strSQL As String,
Dim i As Integer, etc); this will prevent possible errors and confusion, and
will alert you to typos as you enter code (particularly if you declare
variables using mixed case, then type your code in all lowercase - declared
variables will automatically change to match the case of the declaration, so
if something doesn't change you've almost certainly made a typo).

I also suggest that you use indenting within If statements, loops, etc in
your code (as I had in the code I initially posted). When things get more
complicated, you'll find it much easier to follow code sections via their
indentation. You can use the tab key to increase the indentation for a
line, and that indentation will remain in force until you change it; the tab
key will give you as many spaces as are set in the Tab Width box on the
Tools - Options dialog I mentioned in the previous para.

Again, HTH.
 
L

Larry Linson

"FredFred" wrote
For example, the name of a product is Gizmo. . .
stored the photo seperate from the table as
C:\Photos\GizmoPicture.jpg. I have a table with a
"ProductName" Field, and a Text(?) "ProductPicture"
field. And for the Gizmo record, I entered
C:\Photos\GizmoPicture.jpg in the ProductPicture field.
Now, I'm designing the report named "Catalog" that
is going to print the 100 product names with their pictures.
An now I want to put a box with the product picture(s)
into the detail section.

Just for the record "Bound" has some specific meanings in access including
its use in "Bound Object Frame" which may be misleading in this context --
as that is used with pictures stored in OLE Objects, which you probably do
NOT want to do.

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. (In reports,
code that is in the illustrations in the OnCurrent event will be in the
Print event of the Detail Section.)

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
 
T

Tammy

Rob - I thought you might be able to help me. I need a similar function, but
the files are pdf files, not picture files. Would I do something
differently? Thanks in advance!
 
R

Rob Parker

Hi Tammy,

You certainly would need to do something differently. pdf files are not
image files, and will not display in an image control. They may display in
a bound or unbound object control, and you may be able to set up code to
change the source object as the form/report's recordsource changes (via the
current or format event, respectively). I've never done that, and can't
really help. I do recall, from previous posts in some of the Access
newsgroups, that if you do display a .pdf file within an Access form/report,
you can only ever get to the first page of that file.

Sorry I can't help further. If you want someone else to assist, I suggest
that you will probably be better off posting a new question, with a more
exact subject line; this is an old thread, and it's likely that many
possible responders will not be watching it now.

Rob
 

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