Report with photo or not

J

JoJo

Hi!
I have a report containing personal details of members and their photo. If
I set up the query where the field PersonPhoto is not null (this is the field
with the photos path in) the report runs beautifully. However, as soon as I
take out the IS not null criteria in the query the report fails with
following message:

Microsoft Visual Basic - Run-time error '13': Type mimatch.

This is the code:

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

If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = False
End If

End Sub

Please can anyone help me?
 
B

BruceM

You may want to use the Print event, not the Format event.

As I understand your description, the query includes only records in which
PersonPhoto is not null. If so, why are you testing again? If not, I see
that the Else is the same as the Then in terms of the imgPersonPhoto Picture
property. That is, whether or not personphoto is null,
imgPersonPhoto.Picture is personphoto. All you need to do with the Else is
to set the picture control Visible property to False, and then only if it is
a different color from the rest of the report, or has a line around it, or
something like that.
 
N

NetworkTrade

type mismatch means generically that a field defined as text is being
applied to a number field.... or date field applied to a text field,
etc...you probably get the idea

not uncommon when one experiments and rearranges things to lose track of a
field's original definition in table
 
J

JoJo

Sorry for confusion. The report works when I have a picture. When a ercord
doesn't have a picture it won't run because of the mistype error. So what do
I need to take out? Can you be very specific as I don't get VBA (like type
it here?)...
Thanks
 
B

BruceM

You have the following line of code:

Me.imgPersonPhoto.Picture = Me.personphoto

It runs whether or not personphoto is null. However, if personphoto is null
you have, in effect:

Else
Me.imgPersonPhoto.Picture = Null

This is probably the source of the type mismatch error.

Try this:

If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
End If

In other words, remove the Else part of the code. The only reason you would
need it is if imgPersonPhoto has a border or some other formatting you don't
want to see if there is no picture, in which case you could have:

If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
Me.imgPersonPhoto.Visible = False
End If

Now that I think about it, I expect the code will work in the Format event,
but frankly I have trouble sorting out the Format event and the Print event.

Here's something that will help find code errors. Open the VBA editor
(where you copied the code). Click the vertical bar to the left of where
the actual code appears, next to a line of code such as:

If Not IsNull(Me.personphoto) Then

A red dot will appear in the vertical bar, and the line of code will be
highlighted. You have set a break point. To use this, attempt to run the
code by trying to open the report (or by whatever means you were using when
you received the error message). The code will stop at the break point.
Press the F8 key to move to the next line of code. This is called stepping
through the code. Assuming you set the break point where I suggested, after
you press F8 once, point to Me.personphoto. Don't click; just point. After
a moment the value of personphoto should appear. This will let you
determine if the code is producing the expected values, and you will be able
to discover which line of code is causing problems.
When you are done, click again in the VBA editor to clear the break point,
or use the Debug menu to clear all break points.
 
J

JoJo

I'm so happy. This is great - I am beginning to understand this code better
now! As there are now a lot of photos importing each time I run the report
it takes quite a while. Doyou have any suggestion? Is this the difference
between placing the code in the print event as opposed to the format event?
Many thanks
JoJo
 

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