Solved

isnull inside of an iff statement MS Access

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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 …

920 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

17 Experts available now in Live!

Get 1:1 Help Now