View Full Version : does not equal works but equals doesn't.


RECrerar
10-21-2008, 05:50 AM
I have found this a few times whist writing VBA in access, that if I want to see if a field on a form is empty that coding to see if the value is equal to nothing does not work but coding to see if it is not equal to nothing does.

For example:


If cbresponsible = "" Then
' Do Stuff
End If


The above code does not exectute the do stuff even when the combobox in this case is empty.

However


If cbresponsible <> "" Then
Else
' Do Stuff
End If


Will function as would be expected with Stuff exectued when the box is empty but not when it is not.

I've put this in forms as that's what I'm currently working on. Can anyone explain this? It's not exactly a terminal issue but it is confusing.

Rabbie
10-21-2008, 05:55 AM
Empty combo boxes can be either Null or ""(empty string). You could try


If nz(cbresponsible,"") = "" Then
' Do Stuff
End If


It's always tricky with these ones.