Isnull with else if statement

thescottsman92

Registered User.
Local time
Today, 13:15
Joined
Sep 2, 2013
Messages
24
Hi All Please can someone tell me where I am going wrong with this code

ElseIf IsNull((Me.From) Or (Me.Contact) Or (Me.TelephoneNumber) Or (Me.Email)) Then

Thanks for your help
 
Is this what you intend?

ElseIf IsNull(Me.From) Or IsNull(Me.Contact) Or IsNull(Me.TelephoneNumber) Or IsNull(Me.Email) Then
 
I played with or'ing null values in the immediate window and it looks like null is regressive. So if I do true OR null, I get true. 1 or null = 1. null or null or null or 5 = 5
Your OR statement will only return true if every one of your controls returns a null value.
 
Well, you could actually use + and take advantage of how it's treated:

?isnull(null & "")
False
?isnull(null + "")
True

So in theory this should work:

ElseIf IsNull(Me.From + Me.Contact + Me.TelephoneNumber + Me.Email) Then

but in my view less self-documenting.
 
what are you trying to do?

check that all the values are non null?
to be honest I would probably do this
I hardly ever use elseif

Code:
 else
     if isnull(field1) then goto notvalid
     if isnull(field2) then goto notvalid
     if isnull(field3) then goto notvalid
     if isnull(field4) then goto notvalid     
 end if
  
 notvalid:
 
Sometimes I've had issues with "" vs null, where a field is empty but is not null, holding instead an empty string. Get around this by:
If nz(Me.From,"")="" then
'dostuff
End if
'repeat the above for each field. Not as an elseif but as separate ifs
 
Sometimes I've had issues with "" vs null

if your textbox content is but spaces, no matter how much you put, access will remove them, so your textbox content always revert to Null.
 
if your textbox content is but spaces, no matter how much you put, access will remove them, so your textbox content always revert to Null.

That is true using keyboard input but spaces can be entered with code.
 
if your textbox content is but spaces, no matter how much you put, access will remove them, so your textbox content always revert to Null.

Are you sure?

a zls is different to a null.
 

Users who are viewing this thread

Back
Top Bottom