Solved

IsNull using multiple variables

Posted on 2004-08-03
13
575 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
  • 5
  • 3
  • 3
  • +1
13 Comments
 
LVL 80

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 80

Expert Comment

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

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever had the experience that you had to follow 10 steps over and over again every time when you need to nicely forward an important email to your manager? Fear no more! With the help of the Quick Steps feature in Outlook 2010, your old chor…
In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

747 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