Originally Posted by
summerleas
No luck with your suggestions.
IIf(Nz([Exchange],"")="",[SaleNumber],0) fails with the message "The exression IIf(Nz([Exchange],"")="",[SaleNumber],0) cannot be used in a calculated column." (I changed Number to SaleNumber.)
IIf(Nz([Exchange],"")<>"Exchange”,[SaleNumber],0) also fails with the same message.
I googled Nz and found mention of variants, but googling variant did not explain the term! Is this a red herring or relevant?
Why does IIf([Exchange]<>"Exchange",[Number],0) fail? I am not referring to a null value or an empty string.
I tested each of the suggestions here as calculated fields in a query before posting. They worked for me.
id |
NumberField |
TextField |
1 |
1 |
Exchange |
2 |
3 |
|
3 |
23 |
|
4 |
7 |
Exchange |
5 |
4 |
|
6 |
5 |
|
NumberField |
TextField |
NumberExchanged |
NumberNew |
ThisOneFails |
1 |
Exchange |
1 |
0 |
0 |
3 |
|
0 |
3 |
0 |
23 |
|
0 |
23 |
0 |
7 |
Exchange |
7 |
0 |
0 |
4 |
|
0 |
4 |
0 |
5 |
|
0 |
5 |
0 |
Code:
SELECT tblSummerleas.NumberField, tblSummerleas.TextField, IIf([TextField]<>"",[NumberField],0) AS NumberExchanged, IIf(Nz([TextField],"")="",[NumberField],0) AS NumberNew, IIf([TextField]<>"Exchange",[NumberField],0) AS ThisOneFails
FROM tblSummerleas;
Test db attached
When a variable is not properly defined e.g. as an integer number or a string, Access uses the variant type instead - its a 'catch all' that can be anything ... but in normal circumstances its better to define properly. Its a red herring here.
IIf([Exchange]<>"Exchange",[Number],0) should only fail if some values are nulls/ZLS. Nulls are not equal to anything - not even another null - so the expression fails
Test it for yourself by populating the empty records with any text
HTH
Just logging off now as its very late here in the UK