If statement comparing Null = Null

  • Thread starter gmazza via AccessMonster.com
  • Start date
G

gmazza via AccessMonster.com

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!
 
S

Sylvain Lafontaine

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)
 
C

Chegu Tom

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
 
J

Jeff Boyce

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
 
G

gmazza via AccessMonster.com

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

Jeff said:
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
Hey there,
I have a form, it calls a pop up form with a text box in it called
[quoted text clipped - 17 lines]
Please help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top