473,395 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

IIF Statements

54
Hi

I'm using the following IIf statement to populate a field in a report.

Expand|Select|Wrap|Line Numbers
  1. =IIf([SubFormValues2]="",[SubFormValues],IIf([SubFormValues3]="",[SubFormValues]+""+[SubFormValues2],[SubFormValues]+""+[SubFormValues2]+""+[SubFormValues3]))
  2.  
SubFormValues1 (2 and 3) are all from the same query - (I have had to do it like this in the report as in the query the maximum length of 255 characters had been reached in all 3 fields). The problem is when I run the report I get blank fields in every page where SubFormValues2 or SubFormValues 3 has been blank - which basically means that the only time the text appears is when there is information in all 3 fields for the same record i.e. SubFormValues1, 2 and 3. I'm quite stumped by it as the logic seems correct - if subform values 2 is blank just show the first field, if subformvalues 3 is blank just show the first concatenated with the second. else show all 3. Can anyone see what i'm doing wrong?

Thanks for your time!
Feb 19 '10 #1
4 2178
gershwyn
122 100+
If SubFormValues2 and SubFormValues3 contain no data at all, then they are probably Null and not a blank string. If that is the case, then the first two tests will fail (since null is not equal to a blank string) and will get a null value for the final answer. (Any expression that contains a null will evaluate to null, whether or not the other fields contain any data.)

Try this and see if it works:

Expand|Select|Wrap|Line Numbers
  1. =IIf(IsNull([SubFormValues2]),[SubFormValues],IIf(IsNull([SubFormValues3]),[SubFormValues]+" "+[SubFormValues2],[SubFormValues]+" "+[SubFormValues2]+" "+[SubFormValues3]))
That would take care of testing for nulls, assuming you never have a situation where SubFormValues3 has data but SubFormValues2 does not.

I don't know where this data is coming from or how you intend to use it. There is probably a way to what you intend without nested IFs.
Feb 19 '10 #2
topher23
234 Expert 100+
For a more elegant solution, use Nz rather than IsNull (just in case the value actually is an empty string). You should also be able to concatenate the strings by using & rather than +""+

The expression would look something like this:

Expand|Select|Wrap|Line Numbers
  1. =IIf(Nz([SubFormValues2])="", [SubFormValues], 
  2.  IIf(Nz([SubFormValues3])="", [SubFormValues] & [SubFormValues2], 
  3.  [SubFormValues] & [SubFormValues2] & [SubFormValues3])) 
  4.  
If you find yourself doing a lot of nested IIf's, you may also want to look into the Switch function.

Hope this helps!
Feb 19 '10 #3
NeoPa
32,556 Expert Mod 16PB
I would certainly us & instead of + when concatenating these values as with the + any Null values would be propagated (resulting in the whole string being Null). See Using "&" and "+" in WHERE Clause for more on this.
Feb 21 '10 #4
g diddy
54
Thank you very much for the snippet and explanation topher23; I have got it working perfectly now! Also thank you NeoPa for that guide, it was very useful. I didn't realise that there was a difference between & and +!
Feb 22 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Bart Nessux | last post by:
Should an if statement have a corresponding else statement? Or, is it OK to have an if statement by itself. For completeness, it seems the two should be together, but from experience I know that a...
9
by: Jaime Wyant | last post by:
I know I've seen this somewhere, but can't seem to google it. Is there a way to use an alternate statement separator, other than the default ';'? jw
1
by: Tom D | last post by:
I'm rewriting a database interface that our company currently has. Currently it's using the Pear::DB interface, but we found that that was introducing a bit too much overhead. I'm rewriting the...
39
by: slogging_away | last post by:
Hi - I'm running Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32, and have a script that makes numerous checks on text files, (configuration files), so discrepancies can be reported. The script...
0
by: Fuzzyman | last post by:
Hello all, The following is a copy of a blog entry. It's asking a question about future statements and the built in compile function. I'd appreciate any pointers or comments about possible...
20
by: Neroku | last post by:
Hello, i would like to know what the serious definition of statements and expressions is: i know an expression are evaluated to a value, i.e: 1 == 2 5+7 foo( 1,2) and a statement is...
2
by: ojorus | last post by:
Hi! Some questions regarding the mysqli-extension (php5) 1) Prepared statements: If I understand things right, prepared statements will give better performance if you make several similar...
3
by: Dmitri | last post by:
Hello! I have a developer that is playing around with some SQL statements using VB.NET. He has a test table in a SQL 2000 database, and he has about 2000 generated INSERT statements. When the...
0
by: Gary Herron | last post by:
Ohad Frand wrote: There is no way you can consider 'elif', 'else', 'except', and 'from' statements. However, as someone pointed out, the kwlist from the keyword module is the closest thing we...
0
by: Ohad Frand | last post by:
Hi Thanks a lot for your reply I think the main uses for it is to study the language and to see that I didn't miss anything else or that something is changed from one version to another. The...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.