cannot use nz function

J

Jason

I have a query (running the query under queries) that works fine with where
nz(amount)<>0 however when I use currentdb.execute "Update amount=0 where
nz(amount)=0" generates an error.
currentdb.execute "Update amount=0 where iif(isnull(amount),0,amount)=0"

Thanks,
J.
 
J

Jason

I have a query (running the query under queries) that works fine with where
nz(amount)<>0 however when I use
currentdb.execute "Update amount=0 where nz(amount)=0" generates an error.
currentdb.execute "Update amount=0 where iif(isnull(amount),0,amount)=0"
works

maybe I have to use nz(amount,0) even though normally I don't need the comma
and zero.

Thanks,
J.
 
J

John W. Vinson

I have a query (running the query under queries) that works fine with where
nz(amount)<>0 however when I use currentdb.execute "Update amount=0 where
nz(amount)=0" generates an error.
currentdb.execute "Update amount=0 where iif(isnull(amount),0,amount)=0"

Thanks,
J.

This is incorrect syntax for an UPDATE statement: it should be

UPDATE tablename
SET fieldname = <some value>
WHERE <condition>

It SOUNDS like what you want to do is to update a field named Amount to 0 if
it is NULL (updating it to 0 when it is already 0 is pointless). The syntax
would be

CurrentDb.Execute "UPDATE yourtable SET Amount=0 WHERE Amount IS NULL"

If that's not what you're trying to accomplish please explain.
 
J

Jason

The numbers are displaying as zero even though they could be 0.00003 so I am
using the nz function to over come the issue should any values be null.
 
J

John Spencer

UPDATE SomeTable
SET Amount = 0
WHERE Amount is Null or (Amount >0 and Amount <1)

If you want to only change amounts to zero with a smaller range then
change the range to
(Amount >0 and AMount < .0001)
or whatever range you wish to specify.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

The numbers are displaying as zero even though they could be 0.00003 so I am
using the nz function to over come the issue should any values be null.
 
J

Jason

John Spencer said:
UPDATE SomeTable
SET Amount = 0
WHERE Amount is Null or (Amount >-0.001 and Amount <0.001)

If you want to only change amounts to zero with a smaller range then
change the range to
(Amount >0 and AMount < .0001)
or whatever range you wish to specify.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Style Header Reformatted 3
Dynamic Naming of Form Button 3
IIF statement 6
Division by Zero Error 1
Calucation in query 2
Dynamic RecordSet Field Name 4
Past Due Expression 1
Help with small result type 2

Top