Solved

Comparing NULL to "" in MS Access

Posted on 2012-03-18
5
256 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
Comment Utility
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
Comment Utility
ElseIf nz(Me.fldURA_Class_Cat.Value,"") = strOldValue And intAlreadyChanged = 1
0
 
LVL 20

Expert Comment

by:clarkscott
Comment Utility
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
Comment Utility
>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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
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.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

762 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

9 Experts available now in Live!

Get 1:1 Help Now