If statement comparing Null = Null

If statement comparing Null = Null

Post by gmazza via » Fri, 24 Apr 2009 05:12:57


Hey there,
I have a form, it calls a pop up form with a text box in it called txtReason,
as well as a password field.
If the user goes to enter a password without putting a reason then I want it
to MsgBox them to put in a Reason.
The pop up form has no record source. txtReason is unbound, I just need the
value after I close the pop up but it must be entered.
With the code I currently have below in my Password text box Before Update,
when I Debug, it shows txtReason = Null, and Null = Null yet it skips over
the If and goes to the End If, completely baffling me.

If txtReason = Null Then
MsgBox "You must enter a Reason", vbOKOnly, "Message Alert"
txtReason.SetFocus
End If

Please help!

--
Message posted via AccessMonster.com
http://www.yqcomputer.com/
 
 
 

If statement comparing Null = Null

Post by Sylvain La » Fri, 24 Apr 2009 05:28:07

For the Null value, you must use the function isNull or the operator Is
Null:

If txtReason is Null Then

or:

If IsNull (txtReason) Then

--
Sylvain Lafontaine, ing.
MVP - Windows Live Platform
Email: sylvain2009 sylvainlafontaine com (fill the blanks, no spam please)
Independent consultant and remote programming for Access and SQL-Server
(French)

 
 
 

If statement comparing Null = Null

Post by Chegu To » Fri, 24 Apr 2009 05:29:29

You could use the afterupdate event of the password control to check the
txtReason

if nz(txtReason)="" then msgbox "You need to enter a reason Dingbat!!"

Or you can make the password field Locked, disabled, or invisible and change
its status in the after update event of the txtReason box

if not isnull([txtReason]) then me.passwordcontrol.enabled=true or
.visible=true or .locked=false

They will not have the option of entering a password until after they have
entered a reason. no message will be necessary
 
 
 

If statement comparing Null = Null

Post by Mark Andre » Fri, 24 Apr 2009 05:30:56

Try
if (Nz(txtReason,"") = "") then
 
 
 

If statement comparing Null = Null

Post by Jeff Boyc » Fri, 24 Apr 2009 05:42:52

Null means nothing there to measure. You can't compare Null to Null because
there's nothing there!

Check the other responses you've received, and bear in mind, as Mark A's
response suggests, that just because you can't SEE anything doesn't make it
a Null ... it could be a zero-length string ("").

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
 
 

If statement comparing Null = Null

Post by gmazza via » Fri, 24 Apr 2009 05:54:18

Thank you both for your help, it was a zero length string as Mark's syntax
worked. Good to know for next time.



--
Message posted via AccessMonster.com
http://www.yqcomputer.com/