Null value not working

csennett

New member
Local time
Today, 23:40
Joined
Jul 5, 2007
Messages
6
Morning all,

I have a small procedure that checks the value of a text box. If it is 'Null' it should exit the sub. Here it is

Private Sub txtSURICCode_GotFocus()

If txtSURICCode.Value = Null Then
Exit Sub
Else
SURICSNumber = txtSURICCode.Value
End If

End Sub

For some reason the first line 'If txtSURICCode.Value = Null ' is never getting acted on. If I go into debug and hover over to get the value of txtSURICCode it shows as 'Null' so why is the Exit Sub not being acted on ?

Any help appreciated.

Chris
 
use another eventhandler

Hi!

Try to use another eventhandler....:)
 
I've tried OnEnter - not working either.

I need to get the value before any user input or changes
 
why

why Exit sub?
Whats the purpose?
 
I had big reply ready but I just deleted it.

Your reply above about 'Use another event' and me writing down the problem made me think a bit more. I was making it hard for myself.

I used the 'AfterUpdate' event on the text box control and it all sems to be working fine.

i feel stupid.:o
 
not always easy with coding...hehe.
 
Understand the difference between 'Null' and 'Null String'. Null can not be used with a relational operator like >, <, =, <> etc. There is nothing in Null and hence it can not be compared.
So rewite the statement as below
Code:
Private Sub txtSURICCode_GotFocus()

If IsNull(txtSURICCode) = True Then
Exit Sub
Else
SURICSNumber = txtSURICCode.Value
End If

End Sub

For better results you use as below

Code:
Private Sub txtSURICCode_GotFocus()

If txtSURICCode = "" Or IsNull(txtSURICCode) = True Then
Exit Sub
Else
SURICSNumber = txtSURICCode.Value
End If

End Sub
 
Last edited:
Thanks - that was it.

IsNull - how can I forget about that !

Thanks a lot.
 

Users who are viewing this thread

Back
Top Bottom