rondawg
asked on
Comparing NULL to "" in MS Access
ElseIf Me.fldURA_Class_Cat.Value = strOldValue And intAlreadyChanged = 1 Then
Is the code that is not firing properly, fldURA_Class_Cat.Value returns a value of NULL and strOldValue returns a value of "".
Any suggestions???
Is the code that is not firing properly, fldURA_Class_Cat.Value returns a value of NULL and strOldValue returns a value of "".
Any suggestions???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ElseIf nz(Me.fldURA_Class_Cat.Val ue,"") = strOldValue And intAlreadyChanged = 1
Remember, NULLS only refer to fields in tables, text boxes and other objects on forms, reports, etc. "" refers ONLY to text(string) variables.
Scott C
Scott C
>NULLS only refer to fields in tables, text boxes and other objects on forms, reports, etc. "" refers ONLY to text(string) variables.
Were it only so simple. :>)
Were it only so simple. :>)
If you are coming from an Oracle background, you must be aware that Access/SQL Server do not share Oracle's convention for NULL. Oracle uses "" to denote null for all datatype. MS products do not.
I think too, looking at strOldValue that you are discovering, the hard way, that when the end user enters something in a control that was NULL and then backspaces to nothing, the value does not return to NULL, it is changed to "". If they hit ESC, then it will return to NULL.
Now you have a fun little problem! To the end user, NULL and "" look the same. You'd probably be best putting a default value of "" in for the field in the table--that way NULL isn't part of the equation. But there can be reasons not to do that. So handle NULL on both sides of your test
ElseIf nz(Me.fldURA_Class_Cat.Val ue,"") = nz(strOldValue,"") And intAlreadyChanged = 1 Then
Now, no matter what initial state (NULL or "") it was in, you can do something with it if it is appearing blank to the end user.
I think too, looking at strOldValue that you are discovering, the hard way, that when the end user enters something in a control that was NULL and then backspaces to nothing, the value does not return to NULL, it is changed to "". If they hit ESC, then it will return to NULL.
Now you have a fun little problem! To the end user, NULL and "" look the same. You'd probably be best putting a default value of "" in for the field in the table--that way NULL isn't part of the equation. But there can be reasons not to do that. So handle NULL on both sides of your test
ElseIf nz(Me.fldURA_Class_Cat.Val
Now, no matter what initial state (NULL or "") it was in, you can do something with it if it is appearing blank to the end user.