?
Solved

Stuck on syntax

Posted on 2013-01-15
12
Medium Priority
?
149 Views
Last Modified: 2013-01-18
What is wrong with this code?  All I'm trying to do is replace the field with a "0" if the calculated value is less than "0".


=IIf(([txtBalToMake]/[txtPatterns_On])<0,0,=Nz([txtBalToMake]/[txtPatterns_On],1))
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 38778281
=IIf(([txtBalToMake]/[txtPatterns_On])<0,0,Nz([txtBalToMake]/[txtPatterns_On],1))

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 38778288
Or this to avoid errors with nulls:


=IIf( NZ([txtBalToMake,0)/NZ(txtPatterns_On,1)<0,0, NZ([txtBalToMake,0)/NZ(txtPatterns_On,1))

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 38778301
One step further to avoid division by zero if txtPatterns_On is zero:

=IIf( NZ(txtBalToMake,0)/iif(NZ(txtPatterns_On,1) = 0, 1,NZ(txtPatterns_On,1) ) <0,0, NZ(txtBalToMake,0)/iif(NZ(txtPatterns_On,1) = 0, 1,NZ(txtPatterns_On,1) ) 

Open in new window

0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 48

Expert Comment

by:Dale Fye
ID: 38778325
A little slow this morning Miriam?

;-)

Dale

PS - What time zone are you in?  You always seem to get the jump on me, I'm on US Eastern
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38778340
Missed a closing paren :-)

IIf( NZ(txtBalToMake,0)/iif(NZ(txtPatterns_On,1) = 0, 1,NZ(txtPatterns_On,1) ) <0,0, NZ(txtBalToMake,0)/iif(NZ(txtPatterns_On,1) = 0, 1,NZ(txtPatterns_On,1) ) )

Open in new window



Dale,

I'm on the East Coast too, but wake up insanely early.
0
 

Author Comment

by:SteveL13
ID: 38778355
I get a "Enter parameter value"
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38778367
What parameter is it asking for?

Double-check the spelling of the field name...

What I posted at http:#a38778340 is tested, and should work for you assuming that the textbox names are correct.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38778374
You might also want to check the fieldnames in the recordsource of your form or report and also the sorting/grouping if you are working with a report.

(Its possible that something other than this control source is causing that prompt.)
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38778399
You might want to wrap all of the field names in brackets, but that should not be necessary.  I noticed that one of the earlier responses had a missing "]", but I believe mbizup dropped the brackets out of the latest version.

Also, if this is the control source for an unbound textbox, then I would probably go one step beyond  mbizup' last recommendation with:

=iif(NZ(txtPatterns_On,0) = 0, "Invalid Divisor", NZ(txtBalToMake,0)/txtPatterns_On)

This takes the NULL or Zero divisor totally out of the equation.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38778424
are you expecting to get a negative result ? cause - (negative values) are the only ones less than 0  (zero)




try

=IIf(([txtBalToMake]/[txtPatterns_On]) = null,0,Nz([txtBalToMake]/[txtPatterns_On],1))
0
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 38778520
= IIf( NZ(txtBalToMake,0)/iif(NZ(txtPatterns_On,1) = 0, 1,NZ(txtPatterns_On,1) ) <0,0, NZ(txtBalToMake,0)/iif(NZ(txtPatterns_On,1) = 0, 1,NZ(txtPatterns_On,1) ) )

Open in new window

0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38794363
I don't understand how converting a NULL or zero denominator  to a 1 solves anything.  It appears to me that it would be very misleading to your users.  Did you try:

=iif(NZ(txtPatterns_On,0) = 0, "Invalid Divisor", NZ(txtBalToMake,0)/txtPatterns_On)

This makes it very clear that the divisor is not valid for the computation, rather than assuming that it should be 1.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question