Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

IIF results in #Type! in Access

Posted on 2014-02-24
10
Medium Priority
?
579 Views
Last Modified: 2014-03-01
I have an Access report that I want to grab 3 description fields and combine them using IIF so that if a field is null, it doesn't display anything.  I'm trying to use:

=IIf(IsNull([FIELD1]),"","FIELD1 DESC: " & [FIELD1]) & IIf(IsNull([FIELD2]),"","FIELD2 DESC: " & [FIELD2]) & IIf(IsNull([FIELD3]),"","FIELD3: " & [FIELD3])

But I get #Type! errors when I try to display the report.

I'm new to IIF but as I understand it, what I've done SHOULD work... shouldn't it?  Your assistance is appreciated.

I don't think it makes a difference, but to be clear, the data lives in a SQL database and Access is only the front end.
0
Comment
Question by:Lee W, MVP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 22

Assisted Solution

by:Kelvin Sparks
Kelvin Sparks earned 1000 total points
ID: 39884807
Have you tried this in a query first. If it still fails, have you tried each of the three parts on their own?

If all works, where in the report are you using this - that could be your issue.


Kelvin
0
 
LVL 19

Assisted Solution

by:MINDSUPERB
MINDSUPERB earned 1000 total points
ID: 39884845
Hello Lee,

I've seen an issue with your IIF syntax. The IIF Syntax looks the same with the sample below:

=IIf([CountryRegion]="Italy", "Italian", IIf([CountryRegion]="France", "French", IIf([CountryRegion]="Germany", "German", "Some other language")))

You may try to follow the link below for the detailed explanation of the IIF.

http://office.microsoft.com/en-001/access-help/iif-function-HA001228853.aspx

Sincerely,

Ed
0
 
LVL 96

Accepted Solution

by:
Lee W, MVP earned 0 total points
ID: 39884848
WEIRD thing.

(I'm working on a DB someone else created).

Anyway, I had that in what had been a field with ONE field in it - "FIELD1" so I TRIED to use the IIF and add three together (for space reasons, I needed to condense what was 3 separate boxes that rarely had even two used into 1).

Anyway, I went to the query that was pulling the data and tried to make a new field for it - it said I had an extra ) in it.  I looked CLOSELY - I DID NOT!  BUT, I decided to add one field at a time and it worked fine - cutting and pasting what I originally had back in one field and a time.  Go figure.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39884854
I suspect some form of memory issue in Access. I've seen it before where I've had a syntax issue - corrected it, and it keeps repeating the original error. Often you need to delete it totally, develop something else, then rebuild the original.

Have never been able to figure it out, just build techniques for coping with it!

Kelvin
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39884856
Close request OK by me.


Kelvin
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39885262
Why not use a syntax like:

= ("Field1 Desc: " + [Field1]) & ("Field2 Desc: " + [Field2]) & ("Field3: " + [Field3])
0
 
LVL 96

Author Comment

by:Lee W, MVP
ID: 39886167
Because I don't want lines that read "Field1 Desc:" when there is no content in Field1.
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39886380
Lee,

if you notice, I used the "+" to concatenate each field to its description.  

If the field value is NULL, then concatenating it to its descriptive text using the "+" will result in the value inside of the ( ) being NULL.
0
 
LVL 39

Expert Comment

by:PatHartman
ID: 39887215
The reason that the statement didn't work in the report is because the columns were no longer in the report's RecordSource.  Why, you might ask?  The answer is - Because Access is smarter than we are and goes out if its way to help us.  In this case, it knows that the recordset used by the report can be a snapshot since it cannot be updated so it rewrites the select clause and only includes columns which are bound to a control on the report.  It also eliminates the Order By clause since so you MUST use the report's sorting/grouping options to get the report to sort correctly.  Luckily, forms are not so helpful and don't do this to you.

To fix the problem in the future, either create the field in the query (probably the best solution anyway) or bind the columns to controls.  You can make the controls very tiny and set their visible property to no.  I always make hidden controls a garish color that stands out like a sore thumb so it is obvious to me what they are.  You do need to be careful when laying out the report to prevent controls from overlapping.  Can Shrink/Can Grow will not work correctly if there are overlapping controls.  I bind the columns whenever I need to write code in the report's class module so the columns will be available in the code.
0
 
LVL 96

Author Closing Comment

by:Lee W, MVP
ID: 39897036
The steps I took resolved the issue but I appreciate the input and learned a bit from both posters.  Hence the split.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question