Display text if a condition is met (1 Viewer)

Gismo

Registered User.
Local time
Today, 22:20
Joined
Jun 12, 2017
Messages
1,298
Hi all,

Please could you assist?

in a query
If condition 1 is >=1
and condition 2 is >= 1
Display text
Else do nothing

I tried the below as a test but I get a expression invalid syntax
Below only shows one condition as a test

Expr1: IIf([Detailed_Inspections]![CountOfLimit 1]>=1,"Test","")
 

ebs17

Well-known member
Local time
Today, 21:20
Joined
Feb 7, 2020
Messages
1,752
Code:
IIf(Condition1 AND Condition2, ...
You have probably already encountered the fact that you can logically link several things ...?

in a query
If one were to know the statement and the associated data schema, more comprehensive statements might be possible.
 
Last edited:

Minty

AWF VIP
Local time
Today, 20:20
Joined
Jul 26, 2013
Messages
10,330
I think your syntax is off

[Detailed_Inspections]![CountOfLimit 1]

I'm not sure the bang would work here as it's expecting a table reference.

[MyTable].[Myfield]

If the field is only referenced in one table you don't need the table name.
 

Gismo

Registered User.
Local time
Today, 22:20
Joined
Jun 12, 2017
Messages
1,298
I think your syntax is off

[Detailed_Inspections]![CountOfLimit 1]

I'm not sure the bang would work here as it's expecting a table reference.

[MyTable].[Myfield]

If the field is only referenced in one table you don't need the table name.
I removed the table reference, still no luck

Expr1: IIf([CountOfLimit 1]>=1 And [CountOfLimit 2]>=1,"Test","")
also tried
Expr1: IIf([CountOfLimit 1]>=1 And iff( [CountOfLimit 2]>=1,"Test",""))
 

ebs17

Well-known member
Local time
Today, 21:20
Joined
Feb 7, 2020
Messages
1,752
I think your syntax is off
It just says what the expression builder produces.

Some swear by such assistants. The step of writing something yourself and doing so more carefully then becomes more difficult.
 

Minty

AWF VIP
Local time
Today, 20:20
Joined
Jul 26, 2013
Messages
10,330
I removed the table reference, still no luck
Code:
Expr1: IIf([CountOfLimit 1]>=1 And [CountOfLimit 2]>=1,"Test","")

also tried
That looks like it should work.
The access query editor usually will position the cursor where it thinks the syntax error is?

Or does it run and simply say error where the results should be.

Troubles shooting 101, add [CountOfLimit 1] to your query result and display it...
(I would remove the space and rename that result personally - the space in the field name would drive me nuts.)
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:20
Joined
Sep 21, 2011
Messages
13,888
Logic works for me
Code:
SELECT Transactions.ID, Transactions.Clr, IIf([ID]>2094 And [clr]="r","Yes","No") AS Expr1
FROM Transactions;
1692700228313.png
 

Josef P.

Well-known member
Local time
Today, 21:20
Joined
Feb 2, 2023
Messages
763
Code:
Expr1: IIf([Detailed_Inspections]![CountOfLimit 1]>=1,"Test","")
Is the list separator a , or a ;?
The easiest way for helpers would be to see the SQL text.
 

LarryE

Active member
Local time
Today, 12:20
Joined
Aug 18, 2021
Messages
520
Hi all,

Please could you assist?

in a query
If condition 1 is >=1
and condition 2 is >= 1
Display text
Else do nothing

I tried the below as a test but I get a expression invalid syntax
Below only shows one condition as a test
Assuming [CountOfLimit 1] and [CountOfLimit 2] are fields in your query then:
IIf([CountOfLimit 1]>=1 And [CountOfLimit 2]>=1,"Test","")

If [Detailed_Inspections] is an open form (not a subform) and the [CountOfLimit] fields are in the form then:
IIf(Forms![Detailed_Inspections]![CountOfLimit 1]>=1 And Forms![Detailed_Inspections]![CountOfLimit 2]>=1,"Test","")

If [Detailed_Inspections] is an open Report then
IIf(Reports![Detailed_Inspections]![CountOfLimit 1]>=1 And Reports![Detailed_Inspections]![CountOfLimit 2]>=1,"Test","")

If [Detailed_Inspections] is a table which is not part of your query, then you need to use the DLookUp function to get the values asssuming the [CountOfLimit] fields are in that table.
 

Users who are viewing this thread

Top Bottom