How do I get pictures in a report to change with each record?

G

Guest

I have created a form for a realtor that displays a photo which changes with
each record through an image path in the table. When I created the report,
however, the photo that appears is the same from record to record. What am I
missing in the code? There are no error messages.
 
R

Rob Parker

You need code such as this in the On Format event of the report
section in which the image is to be displayed:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.PictureFilename <> vbNullString Then
Me.imgPicture.Picture = pathname & Me.PictureFilename
Me.imgPicture.Visible = True
Else
Me.imgPicture.Visible = False
End If
End Sub

The above assumes that the image is to appear in the detail section, that
the field containing the filename is called PictureFilename, and that the
ImageControl is called imgPicture. Change to suit.

HTH,

Rob
 
S

Stephen Lebans

Hi Rob,
if the OP does not need to change the dimensions of the Image control
then your code is better placed in the Print event of the relevant
section. Tlis will result in less chance of memory/resource issues at
Preview/Print time.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
G

Guest

Thanks guys... I am still unable to display the pictures because of a
compile error: Variable not defined... with the word "pathname" highlighted
in blue.

Any ideas?
Connie :)
 
R

Rob Parker

Sorry Connie,

I copied the code from an application of mine, where I've got the pathname
defined separately, so I'm only storing the filename in the table. If your
PictureFilename includes the path (ie. it's something like
c:\images\mypic.jpg), then simply omit the pathname - the relevant line will
be:
Me.imgPicture.Picture = Me.PictureFilename

HTH,

Rob
 
G

Guest

Dear Rob,

Thank you so much! That did the trick! The pictures are now showing up in
the report in harmony with the realty address! I am so happy!

Connie :)
 
G

Guest

Rob,

My database appears to be laid out similarly, but I get errors when I try
your code. I get "can't find the field 'ImagePath' referred to in your
expression". I've tried various approaches and this one seems the easiest.
Similar coding works fine in forms, but not for reports. I need help

Thanks,

Sean
 
C

CoralN

I keep getting an error with the PictureFilename. It says Compile error:
Method or Data member not found.
 
S

strive4peace

Hi Cora,

firstly -- I cannot see messages before what is under here since I just
added this newsgroup...

the code that Rob gave you needs to have substitutions made by YOU

"Method or Data member not found"

this means that Access cannot find a control you have referenced
Me.imgPicture.Picture = pathname & Me.PictureFilename<

Access must know the "pathname" you are using -- is this a control? My
guess is that you need to supply it... ie:
c:\data\images\"

Me.PictureFilename

in order for this to be recognized, you need to have control with NAME
property = PictureFilename
on your report

read this:

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

Warm Regards,
Crystal

remote programming and training

*
:) have an awesome day :)
*
 

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