A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

#Num!



 
 
Thread Tools Display Modes
  #1  
Old May 26th, 2005, 09:08 PM
Claudette Hennessy
external usenet poster
 
Posts: n/a
Default #Num!

For instance, a calculated field is set to [Amount]/[UnitPrice]. This
results in #Num! on some records. Am looking for an expression that results
in 0 if either [Amount] or [Unit Price] is null.
Claudette Hennessy


  #2  
Old May 26th, 2005, 09:36 PM
Trini Gal
external usenet poster
 
Posts: n/a
Default

Try the Nz function (null to zero function).

Nz([Amount]/[UnitPrice],0)

"Claudette Hennessy" wrote:

For instance, a calculated field is set to [Amount]/[UnitPrice]. This
results in #Num! on some records. Am looking for an expression that results
in 0 if either [Amount] or [Unit Price] is null.
Claudette Hennessy



  #3  
Old May 26th, 2005, 09:38 PM
Ofer
external usenet poster
 
Posts: n/a
Default

iif(isnull([UnitPrice]),0,nz([Amount],0)/[UnitPrice])

You use the NZ function to replace the null with another value, we can do it
to the second number, in that case will get another error "devision by zero",
so we'll use the iif for the second value and the nz for the first value.

"Claudette Hennessy" wrote:

For instance, a calculated field is set to [Amount]/[UnitPrice]. This
results in #Num! on some records. Am looking for an expression that results
in 0 if either [Amount] or [Unit Price] is null.
Claudette Hennessy



  #4  
Old May 26th, 2005, 09:40 PM
Wayne Morgan
external usenet poster
 
Posts: n/a
Default

=Nz(IIf([UnitPrice]=0, 0, [Amount]/[UnitPrice]), 0)

You can't divide by 0 without getting an error, but with either value Null,
the result will be Null. The IIf solves the divide by zero problem, then the
Nz handles the Null result.

--
Wayne Morgan
MS Access MVP


"Claudette Hennessy" wrote in message
...
For instance, a calculated field is set to [Amount]/[UnitPrice]. This
results in #Num! on some records. Am looking for an expression that
results in 0 if either [Amount] or [Unit Price] is null.
Claudette Hennessy



  #5  
Old May 26th, 2005, 10:27 PM
Claudette Hennessy
external usenet poster
 
Posts: n/a
Default

This works if the fields are null, but results in #Name? is the fields are
populated.
"Ofer" wrote in message
...
iif(isnull([UnitPrice]),0,nz([Amount],0)/[UnitPrice])

You use the NZ function to replace the null with another value, we can do
it
to the second number, in that case will get another error "devision by
zero",
so we'll use the iif for the second value and the nz for the first value.

"Claudette Hennessy" wrote:

For instance, a calculated field is set to [Amount]/[UnitPrice]. This
results in #Num! on some records. Am looking for an expression that
results
in 0 if either [Amount] or [Unit Price] is null.
Claudette Hennessy





  #6  
Old May 26th, 2005, 10:27 PM
Claudette Hennessy
external usenet poster
 
Posts: n/a
Default

This results in #Name?

"Wayne Morgan" wrote in message
...
=Nz(IIf([UnitPrice]=0, 0, [Amount]/[UnitPrice]), 0)

You can't divide by 0 without getting an error, but with either value
Null, the result will be Null. The IIf solves the divide by zero problem,
then the Nz handles the Null result.

--
Wayne Morgan
MS Access MVP


"Claudette Hennessy" wrote in message
...
For instance, a calculated field is set to [Amount]/[UnitPrice]. This
results in #Num! on some records. Am looking for an expression that
results in 0 if either [Amount] or [Unit Price] is null.
Claudette Hennessy





  #7  
Old May 26th, 2005, 11:24 PM
Wayne Morgan
external usenet poster
 
Posts: n/a
Default

Then I would also suspect a references error. To see the references, open
the code editor (Alt+F11) and go to Tools|References. For information on
checking these for a problem and to fix them, check here.

http://www.allenbrowne.com/ser-38.html

Another possibility that will cause this is if the control on the form and
the field it is bound to each have the same name. For example, if the Amount
field is bound to a textbox that also has the name Amount. If so, try
changing the textbox's name to txtAmount. Do this for UnitPrice also.

--
Wayne Morgan
MS Access MVP


"Claudette Hennessy" wrote in message
...
This results in #Name?

"Wayne Morgan" wrote in
message ...
=Nz(IIf([UnitPrice]=0, 0, [Amount]/[UnitPrice]), 0)

You can't divide by 0 without getting an error, but with either value
Null, the result will be Null. The IIf solves the divide by zero problem,
then the Nz handles the Null result.



  #8  
Old May 28th, 2005, 01:55 AM
Claudette Hennessy
external usenet poster
 
Posts: n/a
Default

This works! after I changed the textbox names to txtAmount and txtUnitPrice.
thank you very much. Seeing #Num! in a calculated field for new records has
bugged me for a long time.
Claudette Hennessy
"Wayne Morgan" wrote in message
...
=Nz(IIf([UnitPrice]=0, 0, [Amount]/[UnitPrice]), 0)

You can't divide by 0 without getting an error, but with either value
Null, the result will be Null. The IIf solves the divide by zero problem,
then the Nz handles the Null result.

--
Wayne Morgan
MS Access MVP


"Claudette Hennessy" wrote in message
...
For instance, a calculated field is set to [Amount]/[UnitPrice]. This
results in #Num! on some records. Am looking for an expression that
results in 0 if either [Amount] or [Unit Price] is null.
Claudette Hennessy





 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:32 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.