Is Not

kitty77

Registered User.
Local time
Today, 18:27
Joined
May 27, 2019
Messages
715
I'm having some trouble with this...
I can't get the Is Not to work? I basically need the correct use of Is Not.

If ([Mstandard] Is Not "1989") And ([Mfrequency] = "Semi-Annual") Then strDocName = "Report-Semi": MsgBox "Semi-Annual", vbInformation
 
I basically need the correct use of Is Not.
It's: IS [NOT] NULL
The IS operator in SQL can only be used to check for a column value being (not) NULL.
Use the = or <> operators for any comparison with real values other than NULL.
 
Adding to @KitaYama:
Code:
If ([Mstandard] = "1989") = False Then ' ...
' is the same as:
If Not ([Mstandard] = "1989") = True Then ' ...
' is the same as:
If ([Mstandard] = "1989") <> True Then ' ...
' is the same as:
If ([Mstandard] = "1989") = Not True Then ' ...
 
If Not [Mstandard] = "1989" And …….
This will NOT work if Mstandard is null. So, if the column might be null, you need to use IsNull()

If (IsNull(Mstandard) or Mstandard <> "1989") And ([Mfrequency] = "Semi-Annual") Then strDocName = "Report-Semi": MsgBox "Semi-Annual", vbInformation

another method:

If (Mstandard & "" <> "1989") And ([Mfrequency] = "Semi-Annual") Then strDocName = "Report-Semi": MsgBox "Semi-Annual", vbInformation

Concatenating a ZLS to a null value results in a ZLS so this will turn any null into a ZLS which will not be equal to the specified year.
 
Do it this way: NOT ([xxxx] IS NULL) - or - NOT ISNULL([xxxx])

The reason IS NOT NULL doesn't work is because, due to operator precedence rules, you are attempting to evaluate NOT NULL. But that is an expression which means it will propagate the NULL to the expression (NOT NULL). Which means you are attempting to use the IS keyword on a value of NULL. However, the IS keyword only works on the keyword NULL. In essence, when you put the NOT behind the IS, you split a keyword phrase, which ain't gonna work.
 
The reason IS NOT NULL doesn't work is because, due to operator precedence rules, you are attempting to evaluate NOT NULL.
Hmmm.....
The reason IS NOT NULL doesn't work is because it's a different language.
It's SQL, and not VBA.
 
I'm lucky on some days to be able to speak my own language. Thanks for the clarification, David.
 
This will NOT work if Mstandard is null.
My code wasn’t meant to check for nulls because OP hadn’t checked for it in first place. He wanted to know the correct form of using NOT operand and I simply showed that NOT should be used before variable/objectName rather than after.

I basically need the correct use of Is Not.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom