Solved

Comparing NULL to "" in MS Access

Posted on 2012-03-18
5
260 Views
Last Modified: 2012-04-09
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???
0
Comment
Question by:rondawg
5 Comments
 
LVL 12

Accepted Solution

by:
danishani earned 500 total points
ID: 37735420
You can't compare a Null values to a Zero-length-String (""), which are two diferent things.

So in case you want to compare these, you can however convert the Null values to a zero-length-string.

Dim varNull As Variant

If IsNull(Me.fldURA_Class_Cat.Value) Then
 varNull = Me.fldURA_Class_Cat.Value & ""
End If

Hope this helps,
Daniel
0
 
LVL 42

Expert Comment

by:dqmq
ID: 37735421
ElseIf nz(Me.fldURA_Class_Cat.Value,"") = strOldValue And intAlreadyChanged = 1
0
 
LVL 20

Expert Comment

by:clarkscott
ID: 37738179
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
0
 
LVL 42

Expert Comment

by:dqmq
ID: 37738686
>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. :>)
0
 
LVL 26

Expert Comment

by:Nick67
ID: 37754028
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.Value,"") = 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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now