How to deal with a photo when no photo is in folder

D

doyle60

I have a subform with styles (which can have one or more colors) in it
and a field for a photograph for each Style/Color record.

When the user puts his curser on the style or when the record has got
the focus, an image box on the main form shows the photograph of the
style/color. The photos are linked and the event that runs when the
record has the focus is this:

Forms!SelfPrintNewfrm!Photo.Picture = PhotoPathStyle

An example of the text in the field "PhotoPathStyle" would be this:

\\Saint\GroupPhotos\91460SEBlack.jpg

Now all works well.

But when there is NOctual file named "91460SEBlack" in the
"GroupPhotos" folder, I get an error:

Run-time error 2220':
Microsoft Access can't open the file: '\\Saint\GroupPhotos
\91460SEBlack.jpg'.

How can I get rid of this error? When the error occurs what I would
like to happen is for the words "No Photo Available" to appear instead
of a photograph. I can create an actual photograph with the words "No
Photo Available" too. (I solved this problem by having photographs
registered in a table and if they were not on the table, the query
would automatically show the "NO Photo" photograph. But I want to
know if there is a way around this without adding this registration
process.)

By photograph I mean any jpeg, which could be an illustration, but the
files are always jpegs.

Thanks in advance,

Matt
 
D

Douglas J. Steele

Try:


If Len(Dir(PhotoPathStyle)) > 0 Then
Forms!SelfPrintNewfrm!Photo.Picture = PhotoPathStyle
Else
Forms!SelfPrintNewfrm!Photo.Picture = DefaultPathStyle
End If

where DefaultPathStyle points to a default picutre to use when there isn't
one.
 
D

doyle60

I don't think I explained myself well. You see, the query or table
that the sub is based on will always create a photopathstyle. It will
never be null.

So it will create file names for all, some of which will be bogus.

Users will create photos giving them the name [Style] + [ColorCode]
and my query will build it automatically with the same name, whether
it truly exists or not.

It seems to me that the code you are giving me assumes that the field
is null if there is no photo. But when I build this query (or table)
I don't know that. I'm trying to avoid "registering" a photograph. I
could do as you say if I had a user click this or do this or that if a
photo exists. But I'm trying to avoid that step.

Thanks,

Matt
 
D

Douglas J. Steele

I'm not assuming Null anywhere...

If Len(Dir(PhotoPathStyle)) > 0 Then is how you check whether or not a file
path actually exists.
 
D

doyle60

Thanks. I didn't understand the Dir at the time and just assumed you
were doing something else. I looked it up and I used your code, with
changes here and there, and it works wonderfully.

Thanks so much and sorry for my quick idiotic response.

Matt
 

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