Null value not being picked up by if statment

Shaft

Registered User.
Local time
Today, 21:47
Joined
May 25, 2005
Messages
51
Can someone tell me why this doen't work

Code:
If Me.Action_Taken.Value = Null Then
    MsgBox "The 'Action Taken' must be given", vbOKOnly
    GoTo Exit_cmdClose_Reset_Click
End If

I've put a break in at the if statment to check that it does equal null and it does but it still skips over it. WHY?
 
Code:
If Me!Action_Taken & "" = "" Then
    MsgBox "The 'Action Taken' must be given", vbOKOnly
    GoTo Exit_cmdClose_Reset_Click
End If
 
How come if it equals null should you have do this. I've never come across anything like this before.
 
Sorry it does I used a + instead of an &.

Thats the Java slipping in there.
 
Hum... You could do:

Code:
If isnull(Me!Action_Taken) Then
    MsgBox "The 'Action Taken' must be given", vbOKOnly
    GoTo Exit_cmdClose_Reset_Click
End If

But if it happened to contain a zero length string then the if wouldn't catch it. So I just always concatenate a zero len string to what ever is there, and if it's "" or null, "" will show up...

Hope this makes sense... :)
 
I see your thinking now, thanks for help. I still don't understnad why it doesn't pick it up with =null when it does equal null, and that you have to use the isnull.

Anyway it doesn't really matter, it works, Thank you
 
There's also at least one useful place that I can think of to use the '+' when concatenating strings. So don't discard it completely... :)
 
This might be visually easier to understand [just a few more keys strokes of code].

Code:
If IsNull(Action_Taken) Or Action_Taken = "" Then
    MsgBox "The 'Action Taken' must be given", vbOKOnly
    GoTo Exit_cmdClose_Reset_Click
End If
For that will catch the Nulls and the empty strings. Empty strings are created when the user starts to key a value in a field and then they backspace or delete the value. You do not see anything in the field but Access knows that the cell was edited so it is no longer Null but now an empty string.
 

Users who are viewing this thread

Back
Top Bottom