Invalid Syntax - Nz Formula (1 Viewer)

Spam808

Registered User.
Local time
Yesterday, 21:50
Joined
Dec 3, 2018
Messages
55
I am receiving invalid syntax for my formula. A1, A2, and txtAmount is the name of the text box, and they are general numbers.

I need to (A1*A2,"",Round(txtAmount*1200/A1/A2/0,0))

=Nz(Nz([A1,0],0)Nz([A2],0),"",Round(Nz(txtAmount],0)Nz(1200)/Nz([A1,0],0)Nz([A2],0))

Thank you
 

Ranman256

Well-known member
Local time
Today, 00:50
Joined
Apr 9, 2015
Messages
4,337
in Q1, use NZ on the fields that could be null:
Amt: Nz(txtAmount],0)
A1amt: Nz([a1],0)
A2amt: Nz([a2],0)


then do the calc in another query:
Round(Amt*1200/a1Amt/a2Amt)
 

Spam808

Registered User.
Local time
Yesterday, 21:50
Joined
Dec 3, 2018
Messages
55
Thank you, this formula is in a control source of a textbox.
 

JHB

Have been here a while
Local time
Today, 06:50
Joined
Jun 17, 2012
Messages
7,732
I am receiving invalid syntax for my formula. A1, A2, and txtAmount is the name of the text box, and they are general numbers.

I need to (A1*A2,"",Round(txtAmount*1200/A1/A2/0,0))

=Nz(Nz([A1,0],0)Nz([A2],0),"",Round(Nz(txtAmount],0)Nz(1200)/Nz([A1,0],0)Nz([A2],0))

Thank you
Because there are a lot of wrong code/statements:
First take away all the NZ so it isn't disturb you, because it seems that you use the function without thinking, then you can built it up piece by piece.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:50
Joined
Feb 28, 2001
Messages
27,186
Thank you, this formula is in a control source of a textbox.

Because this formula requires so much in the way of pre-checking, this is wrong on multiple counts.

First, you are guaranteed further failure because you are dividing by something that will be zero sometimes (if A1 or A2 came up null). So this is totally wrong.

Then, you are letting all sorts of things distract you with the NZ function.

Here is my take. This function, since it is the .ControlSource of the text box, means the text box is unbound. BUT... if the rest of the form includes some bound items and the underlying record contains A1, A2, and txtAmount, you could compute this using VBA to do all of your fancy-schmancy NZ and divide-by-zero pre-checking in the Form_Current event. Then just post the result of the computation in the textbox.
 

Users who are viewing this thread

Top Bottom