Writing to Null (1 Viewer)

Charles2019

New member
Local time
Today, 06:02
Joined
Mar 24, 2020
Messages
22
I've been running this query IIf([Agent Name] Is Null,"NoName",[Agent Name]) to write NoName to a Null field. Recently, the statement will not write the value in the table with the Null field. I import the table from Excel and have used the LEN statement in Excel to look for hidden characters in the field. Any thoughts on what else I can check or change in the query statement?
 

Isaac

Lifelong Learner
Local time
Today, 04:02
Joined
Mar 14, 2017
Messages
8,778
Maybe it's importing as a zls instead? zero length string
 

plog

Banishment Pending
Local time
Today, 06:02
Joined
May 11, 2011
Messages
11,653
Betting the house on Isaac being right. You can catch Null and empty strings by using NZ to convert nulls to empty strings then testing the size:

Code:
YourFieldName: IIf(Len(Nz([Agent Name], ""))>0,[Agent Name], "NoName")

And your doing yourself (or me) any favors with spaces in your field names. Make it AgentName
 

Charles2019

New member
Local time
Today, 06:02
Joined
Mar 24, 2020
Messages
22
Betting the house on Isaac being right. You can catch Null and empty strings by using NZ to convert nulls to empty strings then testing the size:

Code:
YourFieldName: IIf(Len(Nz([Agent Name], ""))>0,[Agent Name], "NoName")

And your doing yourself (or me) any favors with spaces in your field names. Make it AgentName
I tried your suggested statement and it wasn't successful in writing to the field. Agree on the space in the naming, the entire header row from the import is that way :-( I did an ISBLANK statement in Excel to see what it returned and I got a zero value in the field. So, I'm thinking that's what in the cell.
 

Charles2019

New member
Local time
Today, 06:02
Joined
Mar 24, 2020
Messages
22
I tried your suggested statement and it wasn't successful in writing to the field. Agree on the space in the naming, the entire header row from the import is that way :-( I did an ISBLANK statement in Excel to see what it returned and I got a zero value in the field. So, I'm thinking that's what in the cell.
Success, thanks for all of the help. Pulled a new file, imported it, used the statement above and presto, the field was populated.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:02
Joined
Feb 19, 2002
Messages
43,331
IIf([Agent Name] Is Null,"NoName",[Agent Name])

Should be

IIf(IsNull([Agent Name]),"NoName",[Agent Name])

IsNull() is a VBA function which is what you want to use within another VBA function. "Is Null" is a SQL expression).

I think your original expression should raise an error. It is possible that Access has changed VBA to recognize "Is Null" but it is also possible that SQL is simply ignoring something it doesn't understand.
 

Isaac

Lifelong Learner
Local time
Today, 04:02
Joined
Mar 14, 2017
Messages
8,778
IIf([Agent Name] Is Null,"NoName",[Agent Name])

Should be

IIf(IsNull([Agent Name]),"NoName",[Agent Name])

IsNull() is a VBA function which is what you want to use within another VBA function. "Is Null" is a SQL expression).

I think your original expression should raise an error. It is possible that Access has changed VBA to recognize "Is Null" but it is also possible that SQL is simply ignoring something it doesn't understand.
I thought OP was writing a query?
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 21:02
Joined
Jan 20, 2009
Messages
12,853
IIf([Agent Name] Is Null,"NoName",[Agent Name])

Should be

IIf(IsNull([Agent Name]),"NoName",[Agent Name])

IsNull() is a VBA function which is what you want to use within another VBA function. "Is Null" is a SQL expression).

I think your original expression should raise an error. It is possible that Access has changed VBA to recognize "Is Null" but it is also possible that SQL is simply ignoring something it doesn't understand.
Right idea but based on wrong information.

Iif() is also an engine function. The engine version and the VBA version differ in that one of them evaluates the arguments for both outcomes while the other only evaluates the side that is the result of the test. Forget which way around they are.

Best to continue using Is Null with Iif() because Is Null is also evaluated by the engine while IsNull() is a VBA function.

Also, when testing for both Null and NullString it is far better to use:
Code:
WHEN fieldname Is Null OR fieldname = ""
than:
Code:
WHEN Nz(fieldname,"") =  ""
because the first expression can be evaluated by the engine and use an index if available.

Nz() is a VBA function.

It is better to use Iif() than Nz().
 

June7

AWF VIP
Local time
Today, 03:02
Joined
Mar 9, 2014
Messages
5,488
To handle possibility of Null or empty string: IIf([Agent Name] & "" = "", "NoName", [Agent Name])

But if there are other non-printing characters, none of these expressions will deal with adequately.
 

Users who are viewing this thread

Top Bottom