Solved

Comparing NULL to "" in MS Access

Posted on 2012-03-18
5
262 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

772 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