Solved

isnull inside of an iff statement MS Access

Posted on 2015-01-02
3
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
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…

730 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