Using IIF and 'And' statement in Form (1 Viewer)

Local time
Today, 09:48
Joined
Feb 27, 2022
Messages
49
Hello all,

I've been working on an IIF statement on one of the controls on my form and for over 4 days I can't seem to figure it out- so I thought it's time to reach out for some fresh minds and ideas. :)

Happy to provide more information if required, but I didn't want to bored people with TMI!

Basically I have an IIF statement that uses other fields on the form to return a certain result. When it wasn't working as expected, I've broken down the IIF statement to try and find out where it's falling over and from what I can see, it's not working correctly if I add an 'And' to the IIF statement.

I've tested taking the AND statement out of the formula and if I use either one or the other components, the formula works as expected (so the naming conventions I assume are all correct). As soon as I add the AND back though, the result on the form will always show the 'false' component ("More") when at times it should show the 'true' ("Less")- depending on the other fields on the form off course. There are no error messages showing up either.

Here's the IIF with the And statement:

=IIf(([MinimumRatePurchaseLimit]<>0) And ([TotalOrderAmt]<[MinimumRatePurchaseLimit]),"Less","More")

Could someone please shed some light on this?

Thanking you.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:18
Joined
Oct 29, 2018
Messages
21,453
The expression syntax looks correct. Without seeing the data, it's hard to say why you're getting unexpected results. Are all the fields involved numeric?
 

June7

AWF VIP
Local time
Yesterday, 16:18
Joined
Mar 9, 2014
Messages
5,465
Could either field be Null?
 
Local time
Today, 09:48
Joined
Feb 27, 2022
Messages
49
If the syntax looks correct to you guys, then it seems like there's something I'm missing with the data types that's possibly the problem- so I'll attach a small sample of the database as I see without it, it would be difficult to answer.

@theDBguy: The fields are currency/numerical based.

@June7: The null question is interesting...

The way this form works, is that a user selects a Category at the top of the form and also enters a sales price. Upon selecting a category, you will see some of the other fields on the form change accordingly. Only a few categories have a "Minimum Purchase Rate" value more than $0, otherwise the value in that field should be $0.

So where a category does have a value more than $0 (take 'Beauty' for example which will show $10), then depending on the entered Purchase Price, the IIF statement should adjust accordingly. Hopefully that makes sense.

Thank you.
 

Attachments

  • IfTestDB.zip
    39.2 KB · Views: 241

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:18
Joined
May 7, 2009
Messages
19,231
use Nz() function.
your TotalOrderAmt is Unbound and has no Default value (thus it is Null).

=IIf(([MinimumRatePurchaseLimit]<>0) And (Nz([TotalOrderAmt], 0) < [MinimumRatePurchaseLimit]),"Less","More")
 
Local time
Today, 09:48
Joined
Feb 27, 2022
Messages
49
use Nz() function.
your TotalOrderAmt is Unbound and has no Default value (thus it is Null).

=IIf(([MinimumRatePurchaseLimit]<>0) And (Nz([TotalOrderAmt], 0) < [MinimumRatePurchaseLimit]),"Less","More")
Thanks so much for that. I've never used the Nz function.
 

Users who are viewing this thread

Top Bottom