Solved

Comparing NULL to "" in MS Access

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

839 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