Solved

isnull inside of an iff statement MS Access

Posted on 2015-01-02
3
189 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

791 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