NZ Ain't Easy

  • Thread starter Gaetanm via AccessMonster.com
  • Start date
G

Gaetanm via AccessMonster.com

I have a subform [MYOB_Cards query subform] in that I have a [text30]

in [Text30] Ihave

=NZ(Sum([Price]*[quantity]))

On My MAIN Form I have a Text Box [185] in it I have

=NZ([MYOB_Cards query subform].[Form]![Text30],0)

Text box 185 gives me an #error when there is NULL or no value in [text30].

Text Box 185 returns correct value when there is a value in [text30]

What ist it I'm not seeing

Any help would greatly be appreciated

Gaetanm
 
A

Allen Browne

When there is no value to show, does the subform show a new record? Or does
it go completely blank?

If it shows a new record, you should be fine. If it goes blank, the text box
doesn't exist, and so referring to it yields #Error.

To solve that, test the RecordCount of the subform's RecordsetClone:
=IIf([MYOB_Cards query subform].[Form].[RecordsetClone].[RecordCount] =
0, 0, [MYOB_Cards query subform].[Form]![Text30])

(BTW, that expression fails in Access 2007 for some reason.)
 
G

Gaetanm via AccessMonster.com

Allen
I ran =IIf([MYOB_Cards query subform].[Form].[RecordsetClone].[RecordCount] =

0, 0, [MYOB_Cards query subform].[Form]![Text30])

and it came up with #Name?
I ran my [MYOB_Cards query subform] in Single form and there are,nt any
fields visible excepth the two calculation fields in the form footer and they
are blank.

Maybe if I try to explain what I'm doing (or rather trying to do).

My main form has been used as form that appends data to a [parts] table and a
[time table] table.
Cbo selects {job Id} and the form pulls up parts and labor for that [Job Id].
It totals the total parts cost
and labor cost in their own respective fields.


On my Subform [MYOB_Cards query subform] the Child is matched with master
[Job Id].
The information is gotton from a query based on a accounting software which
the tables
are linked via odbc.
I'm able to add the parts from both forms and make a Grand total on the
Main form.

Here is the crux of the problem (I Think?) When the Child and Master match
but
no records have been put in to the accounting software there are no fields
in my
[MYOB_Cards query subform] and the equation fails #error.

How can I have my total Parts $ on my main form disregard my subform
[MYOB_Cards query subform] parts $ and just calculate the main form parts.
Then
if there is data in [MYOB_Cards query subform] parts calculate the parts in
Main form + parts in [MYOB_Cards query subform]


To try to make the above a nut shell:

Total parts $ in Main + Total Parts $ in [MYOB_Cards query subform] = Main
+ Sub = Main (ToTal)

Total parts $ in Main + No records in [MYOB_Cards query subform] = Main
(ToTal)

No Records in Main + Total Parts $ in [MYOB_Cards query subform] = Sub =
Main (ToTal)

Hope this is not too muddy

Gaetanm

Allen said:
When there is no value to show, does the subform show a new record? Or does
it go completely blank?

If it shows a new record, you should be fine. If it goes blank, the text box
doesn't exist, and so referring to it yields #Error.

To solve that, test the RecordCount of the subform's RecordsetClone:
=IIf([MYOB_Cards query subform].[Form].[RecordsetClone].[RecordCount] =
0, 0, [MYOB_Cards query subform].[Form]![Text30])

(BTW, that expression fails in Access 2007 for some reason.)
I have a subform [MYOB_Cards query subform] in that I have a [text30]
[quoted text clipped - 16 lines]
 
M

Michael Gramelspacher

To try to make the above a nut shell:

Total parts $ in Main + Total Parts $ in [MYOB_Cards query subform] = Main
+ Sub = Main (ToTal)

Total parts $ in Main + No records in [MYOB_Cards query subform] = Main
(ToTal)

No Records in Main + Total Parts $ in [MYOB_Cards query subform] = Sub =
Main (ToTal)
maybe try this:

IIF(Nz(main_form_field) + Nz(subform_field) = Nz(subform_field), Nz
(subform_field),
IIF(NZ(main_form_field) + Nz(subform_field) = Nz(main_form_field), Nz
(main_form_field),
Nz(main_form_field) + Nz(subform_field) = Nz(subform_field)))
 
M

Michael Gramelspacher

To try to make the above a nut shell:

Total parts $ in Main + Total Parts $ in [MYOB_Cards query subform] = Main
+ Sub = Main (ToTal)

Total parts $ in Main + No records in [MYOB_Cards query subform] = Main
(ToTal)

No Records in Main + Total Parts $ in [MYOB_Cards query subform] = Sub =
Main (ToTal)
a little careless with cut and paste, try this:

IIF(Nz(main_form_field) + Nz(subform_field) = Nz(subform_field), Nz
(subform_field),
IIF(NZ(main_form_field) + Nz(subform_field) = Nz(main_form_field), Nz
(main_form_field),
Nz(main_form_field) + Nz(subform_field)))
 
G

Gaetanm via AccessMonster.com

Michael

Thanks for the quick responce. I tried what you suggested and I end up with
the following error.

"The expression you enterd has a function containing the wrong number of
arguments"

Here is my code. Where did I go wrong

=IIF(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([MYOB_Cards
query subform].Form!Text30),NZ([MYOB_Cards query subform].Form!Text30),=IIF
(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([Text185]), NZ(
[Text185]), NZ([Text185]),+ NZ([MYOB_Cards query subform].Form!Text30)))

Gaetanm

Michael said:
To try to make the above a nut shell:
[quoted text clipped - 6 lines]
No Records in Main + Total Parts $ in [MYOB_Cards query subform] = Sub =
Main (ToTal)

a little careless with cut and paste, try this:

IIF(Nz(main_form_field) + Nz(subform_field) = Nz(subform_field), Nz
(subform_field),
IIF(NZ(main_form_field) + Nz(subform_field) = Nz(main_form_field), Nz
(main_form_field),
Nz(main_form_field) + Nz(subform_field)))
 
G

Gary Walter

Hi Gaetanm,

you might try removing "=" before second IIF

there may be other things, but I'd start there...

good luck,

gary

Gaetanm said:
Michael

Thanks for the quick responce. I tried what you suggested and I end up
with
the following error.

"The expression you enterd has a function containing the wrong number of
arguments"

Here is my code. Where did I go wrong

=IIF(NZ([Text185])+NZ([MYOB_Cards query
subform].Form!Text30)=NZ([MYOB_Cards
query subform].Form!Text30),NZ([MYOB_Cards query
subform].Form!Text30),=IIF
(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([Text185]),
NZ(
[Text185]), NZ([Text185]),+ NZ([MYOB_Cards query subform].Form!Text30)))

Gaetanm

Michael said:
To try to make the above a nut shell:
[quoted text clipped - 6 lines]
No Records in Main + Total Parts $ in [MYOB_Cards query subform] =
Sub =
Main (ToTal)

a little careless with cut and paste, try this:

IIF(Nz(main_form_field) + Nz(subform_field) = Nz(subform_field), Nz
(subform_field),
IIF(NZ(main_form_field) + Nz(subform_field) = Nz(main_form_field), Nz
(main_form_field),
Nz(main_form_field) + Nz(subform_field)))
 
M

Michael Gramelspacher

=IIF(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([MYOB_Cards
query subform].Form!Text30),NZ([MYOB_Cards query subform].Form!Text30),=IIF
(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([Text185]), NZ(
[Text185]), NZ([Text185]),+ NZ([MYOB_Cards query subform].Form!Text30)))
=IIF(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([MYOB_Cards
query subform].Form!Text30),NZ([MYOB_Cards query subform].Form!Text30),IIF
(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([Text185]), NZ(
[Text185]), NZ([Text185])+ NZ([MYOB_Cards query subform].Form!Text30)))


but really, this is the same

=(NZ([Text185])+ NZ([MYOB_Cards query subform].Form!Text30))

if both are null, then 0. If one is null, use the other value. If neither are
null, just add the two values.
 
G

Gaetanm via AccessMonster.com

Michael

Hi

Now I'm getting
The expression you enterd contains invalid syntax
You have enterd a coma without a preceding value

=IIF(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([MYOB_Cards
query subform].Form!Text30),NZ([MYOB_Cards query subform].Form!Text30),=IIF
(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([Text185]), NZ(
[Text185])= (NZ([Text185]),+ NZ([MYOB_Cards query subform].Form!Text30)=(NZ(
[Text185])+ NZ([MYOB_Cards query subform].Form!Text30))

Next when I removed the "=" before the second IIf I get the following
statement

The expression you have enterd is missing a closin parenthesis, bracket or
vertical bar

Any Ideas

Gaetanm


Michael said:
=IIF(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([MYOB_Cards
query subform].Form!Text30),NZ([MYOB_Cards query subform].Form!Text30),=IIF
(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([Text185]), NZ(
[Text185]), NZ([Text185]),+ NZ([MYOB_Cards query subform].Form!Text30)))

=IIF(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([MYOB_Cards
query subform].Form!Text30),NZ([MYOB_Cards query subform].Form!Text30),IIF
(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([Text185]), NZ(
[Text185]), NZ([Text185])+ NZ([MYOB_Cards query subform].Form!Text30)))

but really, this is the same

=(NZ([Text185])+ NZ([MYOB_Cards query subform].Form!Text30))

if both are null, then 0. If one is null, use the other value. If neither are
null, just add the two values.
 
M

Michael Gramelspacher

Michael

Hi

Now I'm getting
The expression you enterd contains invalid syntax
You have enterd a coma without a preceding value

=IIF(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([MYOB_Cards
query subform].Form!Text30),NZ([MYOB_Cards query subform].Form!Text30),=IIF
(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([Text185]), NZ(
[Text185])= (NZ([Text185]),+ NZ([MYOB_Cards query subform].Form!Text30)=(NZ(
[Text185])+ NZ([MYOB_Cards query subform].Form!Text30))

Next when I removed the "=" before the second IIf I get the following
statement

The expression you have enterd is missing a closin parenthesis, bracket or
vertical bar

Any Ideas

Gaetanm


Michael said:
=IIF(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([MYOB_Cards
query subform].Form!Text30),NZ([MYOB_Cards query subform].Form!Text30),=IIF
(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([Text185]), NZ(
[Text185]), NZ([Text185]),+ NZ([MYOB_Cards query subform].Form!Text30)))

=IIF(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([MYOB_Cards
query subform].Form!Text30),NZ([MYOB_Cards query subform].Form!Text30),IIF
(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([Text185]), NZ(
[Text185]), NZ([Text185])+ NZ([MYOB_Cards query subform].Form!Text30)))

but really, this is the same

=(NZ([Text185])+ NZ([MYOB_Cards query subform].Form!Text30))

if both are null, then 0. If one is null, use the other value. If neither are
null, just add the two values.
The query from your last message is not the query I sent; it is the same one
you had the problem with. The one I sent did not have ,=IIF at the end of the
second line and it did not have NZ([Test185]),+ NZ in the last line. And did
you note my thought that an IIF expression is not even needed?
 
A

AccessVandal via AccessMonster.com

Hi Gaetanm,

Did you change the "=NZ(Sum([Price]*[quantity]))" to "=NZ(Sum([Price]*
[quantity]),0)" ?

I don't see anything wrong with this, except the above.
"=NZ([MYOB_Cards query subform].[Form]![Text30],0)"
Gaetanm wrote:
I have a subform [MYOB_Cards query subform] in that I have a [text30]

in [Text30] Ihave

=NZ(Sum([Price]*[quantity]))

On My MAIN Form I have a Text Box [185] in it I have

=NZ([MYOB_Cards query subform].[Form]![Text30],0)

Text box 185 gives me an #error when there is NULL or no value in [text30].

Text Box 185 returns correct value when there is a value in [text30]

What ist it I'm not seeing

Any help would greatly be appreciated

Gaetanm
 
G

Gaetanm via AccessMonster.com

Michael and AccessVandal

I went back and with what I have and what you suggested Michael, I did it
with and without the IIF
and it came back with ERROR here is the code

=(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([MYOB_Cards
query subform].Form!Text30),NZ([MYOB_Cards query subform].Form!Text30),(NZ(
[Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([Text185]),NZ(
[Text185]),NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)))

I don't know where I would put the following staement is needed

=NZ([MYOB_Cards query subform].[Form]![Text30],0)

Hi Gaetanm,

Did you change the "=NZ(Sum([Price]*[quantity]))" to "=NZ(Sum([Price]*
[quantity]),0)" ?

I don't see anything wrong with this, except the above.
"=NZ([MYOB_Cards query subform].[Form]![Text30],0)"
Gaetanm wrote:
I have a subform [MYOB_Cards query subform] in that I have a [text30]
[quoted text clipped - 16 lines]
 
A

AccessVandal via AccessMonster.com

Hi Gaetanm,

Have you tried your original code? Because [Text30] is Null, [Text185] cannot
calculate the value or read the value, so you need to change [Text30] = NZ
(Sum([Price]*[quantity]),0). So, whenever [Text30] is Null the Nz function
set [Text30] to "0".
Gaetanm wrote:
Michael and AccessVandal

I went back and with what I have and what you suggested Michael, I did it
with and without the IIF
and it came back with ERROR here is the code

=(NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([MYOB_Cards
query subform].Form!Text30),NZ([MYOB_Cards query subform].Form!Text30),(NZ(
[Text185])+NZ([MYOB_Cards query subform].Form!Text30)=NZ([Text185]),NZ(
[Text185]),NZ([Text185])+NZ([MYOB_Cards query subform].Form!Text30)))

I don't know where I would put the following staement is needed

=NZ([MYOB_Cards query subform].[Form]![Text30],0)
 
G

Gaetanm via AccessMonster.com

Hello , AccessVandal

Sorry I forgot to mention that I did put = NZ(Sum([Price]*[quantity]),0) into
[text30].
I put my subform into single view [text30] { in the form footer} is blank and
there are no other
fields showing in my subform.That is until data is present then all the
fields show up and [text30}adds

I created a field unbound in my sub called it [TEST], changed my [Text30] to
the following
=NZ(Sum([Price]*[test]),0) when no data [text30] is blank. With data in the
form but NO data
in [test] #ERROR occurs

This is driving me nuts

Gaetanm



Hi Gaetanm,

Have you tried your original code? Because [Text30] is Null, [Text185] cannot
calculate the value or read the value, so you need to change [Text30] = NZ
(Sum([Price]*[quantity]),0). So, whenever [Text30] is Null the Nz function
set [Text30] to "0".
Gaetanm wrote:
Michael and AccessVandal
[quoted text clipped - 11 lines]
=NZ([MYOB_Cards query subform].[Form]![Text30],0)
 
G

Gaetanm via AccessMonster.com

Hi guys

I have just figured it out on that error message

=Val(NZ(Sum([Price]*[quantity]),0))

Instead of

=NZ(Sum([Price]*[quantity]),0))

This is what I found

Remarks

The Val function stops reading the string at the first character it can't
recognize as part of a number. Symbols and characters that are often
considered parts of numeric values, such as dollar signs and commas, are not
recognized. However, the function recognizes the radix prefixes &O (for octal)
and &H (for hexadecimal). Blanks, tabs, and linefeed characters are stripped
from the argument

Hello , AccessVandal

Sorry I forgot to mention that I did put = NZ(Sum([Price]*[quantity]),0) into
[text30].
I put my subform into single view [text30] { in the form footer} is blank and
there are no other
fields showing in my subform.That is until data is present then all the
fields show up and [text30}adds

I created a field unbound in my sub called it [TEST], changed my [Text30] to
the following
=NZ(Sum([Price]*[test]),0) when no data [text30] is blank. With data in the
form but NO data
in [test] #ERROR occurs

This is driving me nuts

Gaetanm


Hi Gaetanm,
[quoted text clipped - 8 lines]
=NZ([MYOB_Cards query subform].[Form]![Text30],0)
 
A

AccessVandal via AccessMonster.com

Hi, Gaetanm,

In this case, the Column/Fields in that table for "Price" and "quantity"
DataType must "Text"?

Make sure they are of DataType = Number or Currency. The function calculate
"Text" DataType.
Gaetanm wrote:
Hi guys

I have just figured it out on that error message

=Val(NZ(Sum([Price]*[quantity]),0))

Instead of

=NZ(Sum([Price]*[quantity]),0))

This is what I found

Remarks

The Val function stops reading the string at the first character it can't
recognize as part of a number. Symbols and characters that are often
considered parts of numeric values, such as dollar signs and commas, are not
recognized. However, the function recognizes the radix prefixes &O (for octal)
and &H (for hexadecimal). Blanks, tabs, and linefeed characters are stripped
from the argument
Hello , AccessVandal
[quoted text clipped - 20 lines]
=NZ([MYOB_Cards query subform].[Form]![Text30],0)
 
A

AccessVandal via AccessMonster.com

Re-editing my message...

Hi, Gaetanm,

In this case, the Column/Fields in that table for "Price" and "quantity"
DataType must be "Text"?

Make sure they are of DataType = Number or Currency. The function "Sum([Price]
*[quantity])" cannot calculate "Text" DataType.
 

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

Top