Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Comparing NULL to "" in MS Access

Posted on 2012-03-18
5
Medium Priority
?
276 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

782 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