Solved

IsNull using multiple variables

Posted on 2004-08-03
13
581 Views
Last Modified: 2008-03-10
the help for IsNULL states "If expression consists of more than one variable, Null in any constituent variable causes True to be returned for the entire expression." what is the syntax for specifying multiple variables?

I'm working in Access and want to check several (mandatory) fields and was wondering if the was a short version of

If IsNull(field1) = true OR IsNull(field2) = true OR  IsNull(field3) = true THEN

Thanks

Mandy
0
Comment
Question by:MandyC
[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
  • 5
  • 3
  • 3
  • +1
13 Comments
 
LVL 81

Expert Comment

by:byundt
ID: 11704342
Hi MandyC,
In Excel VBA, I might try something like:
If IsNull(field1)+IsNull(field2)+IsNull(field3)>0 Then

Cheers!

Brad
0
 
LVL 3

Author Comment

by:MandyC
ID: 11704489
Brad,

for what I'm after <0 works (trying to find out if ANY field is null) but was hopping to get rid of those extra IsNull statements as in some cases I'm be checking a lot more than 3 variables.
0
 
LVL 81

Expert Comment

by:byundt
ID: 11704519
MandyC,
I could move this question into the Access TA if you would like.
Brad
0
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!

 
LVL 3

Author Comment

by:MandyC
ID: 11704599
The reason I put it here is that IsNull solutions from Excel (and possibly Word/Project/ VB etc) may work. I'm never too sure what to to with vba questions but am happy to be guided by your experience. Perhaps a vba section under MS Office would be appropriate. (Or the ability to link a question to more that one topic)

I'll leave it up to you to do what you think is best.

Cheers
Mandy

:-)
0
 
LVL 81

Expert Comment

by:byundt
ID: 11704775
Mandy,
The preferred way of asking a question in several forums is to use Pointer questions that direct participating experts to your original question. That way, all the comments are captured in one place. The Pointer questions are deleted (with points refund) when the main question has been answered.

I posted one for you at http://www.experts-exchange.com/Databases/MS_Access/Q_21080532.html
byundt--Office TA Page Editor
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 125 total points
ID: 11704828
u could try this method

use the TAG property, give it a value to indicate that this is a mandatory field, say u put in 1 to indicate this

then in your code

    Dim ctl As Control
    Dim bNullsFound as Boolean

    bNullsFound=False
    For Each ctl In Me.Controls
        If ctl.Tag = 1 Then
            if NZ(ctl.Value,"") = "" Then
                 bNullsFound = True
            endif
         End if
    Next
 
    if bNullsFound = True then msgbox "one or more fields are empty"


0
 
LVL 39

Expert Comment

by:stevbe
ID: 11704963
You can use the + version of concatenation. If the expression on either side is null then the return for + is null

If IsNull((Field1 + Field2 + Field3)) Then
    Msgbox "bad record :)"
End If

Steve
0
 
LVL 39

Expert Comment

by:stevbe
ID: 11705008
Are you doing this for an Access form?
Are the fields marked as "Required" in the table?


Steve
0
 
LVL 3

Author Comment

by:MandyC
ID: 11705082
Stevbe

I tried something similar (used "&" rather than "+" but I don't think that that should matter) but that only worked if ALL the fields were null rather than if ANYof them were.

Also the access form is a front end to SQL so the required element is set there.



Rockiroads

I hadn't come across Tag before but i like it. That was the sort of thing I'm after.

Thanks
0
 
LVL 3

Author Comment

by:MandyC
ID: 11705102
Also thanks to Brad for adding the link (especially if rockiroads followed the link)
M
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 11705121
Urm, I did


hey byundt, thanks
0
 
LVL 39

Expert Comment

by:stevbe
ID: 11705219
"used "&" rather than "+" but I don't think that that should matter"

it does matter,  & and + are different functions ...

test in the debug window ...

?"My" & Null & " Test"
My Test

?"My" + Null + " Test"
Null

Steve
0
 
LVL 3

Author Comment

by:MandyC
ID: 11705325
Stevbe

Thanks - I've posted a question in the MSOffice area to give you the points as well

<<At http://www.experts-exchange.com/Applications/MS_Office/Q_21080620.html
byundt--Office TA Page Editor>>
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
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.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

696 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