Problems with IsNull

helloworld

Registered User.
Local time
Today, 03:38
Joined
May 18, 2004
Messages
62
Hey there,

can someone perhaps explain this little problem to me? It regards an IsNull statement within an If statement.

sometimes when I go...

if (isnull(forms!formname!nameoffield) = true) then.... the statement works

at other times, when I go

if (isnull(forms!formname!nameoffield) = true) then.... the statement does not work

however, if I change that statement to

if (forms!formname!nameoffield = "") then.... it begins to work again.

Is there a bug in Access or is there something I am doing wrong? Your help would be much appreciated.

Thanks
 
Two points:

1. This is wrong:

if (isnull(forms!formname!nameoffield) = true) then

It should be:

if isnull(forms!formname!nameoffield) = true then

2. An if statement assumes you want to check to see if the condition is true so you can omit that part of code. Exp:

if isnull(forms!formname!nameoffield) = true then

Is the same as:

if isnull(forms!formname!nameoffield) then

Hope this helps...
 
This is wrong:

if (isnull(forms!formname!nameoffield) = true) then

It should be:
if isnull(forms!formname!nameoffield) = true then


Thanks for the reply, but is this also true when you have multiple parameters in an if statement?

ex: If isnull(...) = true and isnull(...)=false then....

what I tend to do is put both those parameters in brackets so it is a bit easier to read.

If (isnull(...) = true) and (isnull(...)=false) then....
 
Your second way is what I would use:

If (isnull(...) = true) and (isnull(...)=false) then....

In this case both conditions would have to be true. You can embed these several layers deep:
 
Ahhh...it is making a little more sense now...b/c my code would not fire when one was 'True' and one was 'False'.

I had to use "" for one of them. Thanks for the help man. As a side note, where do I find documentation that explains these rules? These forums have been a great help but I cannot find any sources of documentation that goes into these little details.
 
I poked around in the access help stuff and about all I could find on the spur of the moment that was relevant was a section on 'Operator Precedence'.

Two key things I try remember is the standard order of operations, or, what will access do first, second, and so on when it encounters a compound expression. And it's basically like standard math. It does the inside parenthesis first then works it way outward. Also it does mult. and div. first then add and subtraction.

The last thing is to keep and eye out for functions. That is, anything that has the () at the end, such as isnull() or dLookup(). They usually will return a value, that is when you see isnull(abc), try to see this function as either 'true' or 'false'.

If you haven't built a custom function, try it. All kinds of possibilites open up when realize their potential...
 
Thanks for your help Ken...when I thought about it a bit more, I realized I had to go back to the good old Truth Tables in order to find out what is wrong. Also since an 'If' statement returns a boolean and so does the IsNull() function, the issue of Double negatives came up. But thanks a lot for your help!
 
'Also since an 'If' statement returns a boolean and so does the IsNull() function, the issue of Double negatives came up.'

Do go just yet! Elaborate please!
 

Users who are viewing this thread

Back
Top Bottom