if not isNull with wrong result (1 Viewer)

cpampas

Registered User.
Local time
Today, 02:06
Joined
Jul 23, 2012
Messages
218
Hello everybody,
i do have the following if then condition:

Code:
If Not IsNull(Forms![frmMagicCont]![Procura de Documentos].[Form]![DataM]) Then
      a=1
else
     a=2
end if

in my inmediate window i checked the value of the DataM control, and it returns nothing, i also tested the lenght with :
len(Forms![frmMagicCont]![Procura de Documentos].[Form]![DataM])
and it returns 0

so why, when running the if condition, the code goes to the line a=1
Any toughts about this ?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:06
Joined
May 21, 2018
Messages
8,463
It is possible to have a zero length string. So the better check is
If (Forms![frmMagicCont]![Procura de Documentos].[Form]![DataM] & "") = ""
this handles null and zls
However zls is pretty hard to create, so there may be something else.
 

cpampas

Registered User.
Local time
Today, 02:06
Joined
Jul 23, 2012
Messages
218
I noticed that this behaviour happens after i press a button in the form where the text control is located , and by pressing that button I delete the text in the textbox

Me.DataM = ""

after this is done if i run the if then condition , i get the undesired result, but if i close the form and then open it again then when I run the if then condition i get a=2 ( wich is the correct result)
the control and form are unbound, so I would exclude any requery or refresh issues
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:06
Joined
Sep 21, 2011
Messages
14,050
I noticed that this behaviour happens after i press a button in the form where the text control is located , and by pressing that button I delete the text in the textbox

Me.DataM = ""

after this is done if i run the if then condition , i get the undesired result, but if i close the form and then open it again then when I run the if then condition i get a=2 ( wich is the correct result)
the control and form are unbound, so I would exclude any requery or refresh issues
So YOU create a ZLS by deleting the text?
Then you open the form afresh, with an unbound control (that will be Null?) :unsure:
 

bastanu

AWF VIP
Local time
Today, 02:06
Joined
Apr 13, 2010
Messages
1,401
Because you're not "deleting" the data, you set it as a zero length string(ZLS). Try using Me.DataM = Null instead.

Cheers,
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:06
Joined
May 21, 2018
Messages
8,463
It is possible to have a zero length string. So the better check is
If (Forms![frmMagicCont]![Procura de Documentos].[Form]![DataM] & "") = ""
this handles null and zls
However zls is pretty hard to create, so there may be something else.
Thanks for proving my point. Creating a ZLS is pretty hard to do, but doing it on purpose is one way. Importing from Excel is another common means.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:06
Joined
Feb 19, 2002
Messages
42,981
To summarize:
"" and Null are not the same thing. Depending on what's in your table, you can run a query:

Select somefield, count(*) as RecCount
From YourTable
Group by somefield;

You will see two "empty" lines if the table contains both ZLS and nulls in the same field.

And just to state the obvious, ZLS is a STRING and so it is invalid when applied to a numeric field.

Me.MyDate = "" --- will raise an error
Me.MyDate = Null --- will not raise an error unless you have made MyDate required.
 

cpampas

Registered User.
Local time
Today, 02:06
Joined
Jul 23, 2012
Messages
218
for the kind help thank you all
Me.MyDate = Null, works just great
 

Users who are viewing this thread

Top Bottom