Solved

IIF results in #Type! in Access

Posted on 2014-02-24
10
553 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
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 22

Assisted Solution

by:Kelvin Sparks
Kelvin Sparks earned 250 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 250 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 95

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
 
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39885262
Why not use a syntax like:

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

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 47

Expert Comment

by:Dale Fye (Access MVP)
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 34

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 95

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
I have a large data set and a SSIS package. How can I load this file in multi threading?
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

948 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now