Link to home
Start Free TrialLog in
Avatar of MandyC
MandyC

asked on

IsNull using multiple variables

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
Avatar of byundt
byundt
Flag of United States of America image

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

Cheers!

Brad
Avatar of MandyC
MandyC

ASKER

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.
MandyC,
I could move this question into the Access TA if you would like.
Brad
Avatar of MandyC

ASKER

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

:-)
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 https://www.experts-exchange.com/questions/21080532/125-Point-Question-on-using-multiple-IsNull-tests-in-a-single-VBA-statement.html
byundt--Office TA Page Editor
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Are you doing this for an Access form?
Are the fields marked as "Required" in the table?


Steve
Avatar of MandyC

ASKER

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
Avatar of MandyC

ASKER

Also thanks to Brad for adding the link (especially if rockiroads followed the link)
M
Urm, I did


hey byundt, thanks
"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
Avatar of MandyC

ASKER

Stevbe

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

<<At https://www.experts-exchange.com/questions/21080620/Points-for-stevbe.html
byundt--Office TA Page Editor>>