does not equal works but equals doesn't.

RECrerar

Registered User.
Local time
Today, 04:53
Joined
Aug 7, 2008
Messages
130
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:

Code:
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

Code:
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.
 
Empty combo boxes can be either Null or ""(empty string). You could try

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

It's always tricky with these ones.
 

Users who are viewing this thread

Back
Top Bottom