Solved

IIF results in #Type! in Access

Posted on 2014-02-24
10
552 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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

760 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