Access Database - Display Image if it exists

  • Thread starter Thread starter Ryan Johnson
  • Start date Start date
R

Ryan Johnson

I found out how to display an image that would be associated with a
person in the DRW. After I got this going I noticed that if there is
no value in the Image field of my database it will display a broken
link. Does anyone know how I can maybe say in my query to display the
Image only if it exists?

Here's my query:

SELECT FirstName, LastName, JohnsonBranch, RelationshipToBranch,
Autobiography, Image FROM Registration WHERE (FirstName LIKE
'%::FirstName::%' AND LastName LIKE '%::LastName::%' OR Autobiography
LIKE '%::FirstName::%' AND Autobiography LIKE '%::LastName::%') ORDER
BY FirstName ASC,LastName ASC,JohnsonBranch ASC,RelationshipToBranch
ASC

Thanks,

Ryan
 
Not sure if this will work as it's been a while since I crafted SQL against
Access, but basically what you want to verify is that the Image field is not
null. You should be able to and this to your query like Image IS NOT NULL
AND... I would put it at the beginning so that hopefully Access can improve
performance by automatically ignoring the empty image fields and not bother
matching the other items.

SELECT FirstName, LastName, JohnsonBranch, RelationshipToBranch,
Autobiography, Image FROM Registration WHERE (Image IS NOT NULL AND
FirstName LIKE '%::FirstName::%' AND LastName LIKE '%::LastName::%' OR
Autobiography
LIKE '%::FirstName::%' AND Autobiography LIKE '%::LastName::%') ORDER
BY FirstName ASC,LastName ASC,JohnsonBranch ASC,RelationshipToBranch
ASC


Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
I presume the Image field contains the HTML for an <img>
tag. I so, just make sure not to generate that tag if no
filename is present.

This will probably be easiest if Registration is a query,
or if you make a query that points to the Registration
table. In that case, you would put the image filename only
(and not the surrounding HTML) in a field named, say,
imagefile, and then code:

SELECT Iif(''&[imagefile]='','','<img src="'&[imagefile]
&'">') AS Image, ...

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 

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

Back
Top