Solved

isnull inside of an iff statement MS Access

Posted on 2015-01-02
3
184 Views
Last Modified: 2015-01-02
I'm having some trouble working out using the isnull within an if statement (MS Access 2003).

Things looks roughly like this -
MEDMRKUP - MEDMIN - IVMRKUP - IVMIN: IIf([GEN_DISP_UNIT]="DPU",[MED_PVAR1_DPU],[MED_PVAR1_DPD])+".....
the [MED_PVAR1_DPU] and [MED_PVAR1_DPD] might be null.
0
Comment
Question by:ghettocounselor
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
Nick67 earned 500 total points
ID: 40528106
+ is usually ONLY used for numeric
& is the usual concatenator for strings

The thing is, that + can do some very, very neat things (in Access only) when null gets involved
@harfang wrote a very neat article about that here
http://www.experts-exchange.com/Database/MS_Access/A_2040-Concatenation-in-Access-Reports-and-Forms.html
Even if this is NOT something you are pursuing, this is worth reading.

Generally in Access, if something can be null and we have to deal with that, we use the Nz() function.
Nz is basically an isnull and if rolled together
Nz(ValueThatMayBeNull, WhatToReplaceTheNullValueWith)

Nz is the exact same as SQL Server's ISNull() function.
Where things get confusing is that Access also has an ISNull() function.
All it does, is return TRUE if that value is NULL and False if it is not.

ISNull(SomeNullValue) will equal TRUE
ISNull(SomeNonNullValue) will equal FALSE

I rarely use it -- because 99% of the time, if you are testing for null, you want to immediately deal with it -- and that's what Nz() is for!
0
 

Author Comment

by:ghettocounselor
ID: 40528242
Decided on this tactic:
  = UCase([LastName]) & ', ' & [FirstName] & ' ' & [Initial] & '. (' & [Title] & ')'

This shows as "DOE, John A. (Dr)". This is nice unless there is no middle initial or no title: "DOE, John . ()". If needed, Null values can be converted using Nz(). For example, display "nmi" for "no middle initial" or "?" for missing title:

        ... & Nz([Initial], 'nmi')
from link in selected resolution.

seems to be working as expected:
MEDMRKUP - MEDMIN - IVMRKUP - IVMIN: IIf([GEN_DISP_UNIT]="DPU",Nz([MED_PVAR1_DPU],'ndpu'),Nz([MED_PVAR1_DPD],'ndpd'))+" ....
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40528276
 = UCase([LastName]) & ', ' & [FirstName] & ' ' & [Initial] & '. (' & [Title] & ')'
That looks like a ControlSource for a textbox on a form.
That's a place where @Harfang's nice little trick will work
 = UCase([LastName]) & ', ' & [FirstName] + ' ' & [Initial] & '. ' + (' & [Title] & ')'
As a ControlSource for a textbox, this will collapse to "DOE, John"  when the initial and title are null

MEDMRKUP - MEDMIN - IVMRKUP - IVMIN: IIf([GEN_DISP_UNIT]="DPU",Nz([MED_PVAR1_DPU],'ndpu'),Nz([MED_PVAR1_DPD],'ndpd'))+" ....
This looks like it's from a query, and that's pretty much the only way to do it.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

744 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

12 Experts available now in Live!

Get 1:1 Help Now