Solved Multiple condition in access query builder (1 Viewer)

Tor_Fey

Registered User.
Local time
Today, 02:30
Joined
Feb 8, 2013
Messages
121
Afternoon all;

Is it possible to use the query builder to set the criteria of a field in an access query?

An example of what i want to do is as follows:

Field Name:
Code:
 Selected: (IIf([Rtrd_EdrDate]=[Tret_DateFrom],"First Return") Or IIf([Rtrd_Status]="21","Possible Final Return") Or IIf([Box5]<-900000,"Above Upper Limit"))

I have used the above code but it doesn't work for multiple field criteria, any help would greatly be appreciated.

Kind Regards
Tor Fey
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:30
Joined
Oct 29, 2018
Messages
21,454
Yes, you can use the query builder to add your multiple criteria. However, it has a limited number of rows to construct OR conjunctions. As a workaround, you could try entering multiple criteria in the same cell.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:30
Joined
May 7, 2009
Messages
19,229
you can also use Switch function:

Selected: Switch([Rtrd_EdrDate]=[Tret_DateFrom],"First Return", [Rtrd_Status]="21","Possible Final Return", [Box5]<-900000,"Above Upper Limit", True, Null)

note that Box5 there should be a field? or prefix it with the form name if it is control on the form, ei:

[Forms]![formName]![Box5] < -900000, ...
 

SHANEMAC51

Active member
Local time
Today, 04:30
Joined
Jan 28, 2022
Messages
310
Is it possible to use the query builder to set the criteria of a field in an access query?
this is unlikely to work in
Code:
Selected:
 (IIf([Rtrd_EdrDate]=[Tret_DateFrom],"First Return")
 Or IIf([Rtrd_Status]="21","Possible Final Return")
 Or IIf([Box5]<-900000,"Above Upper Limit"))
try another way (1-14 attachment levels)
Code:
Selected:
 IIf([Rtrd_EdrDate]=[Tret_DateFrom],"First Return",
 IIf([Rtrd_Status]="21","Possible Final Return",
 IIf([Box5]<-900000,"Above Upper Limit","")))

and maybe you need to use a semicolon instead of commas
 

plog

Banishment Pending
Local time
Yesterday, 20:30
Joined
May 11, 2011
Messages
11,638
You shouldn't try and cram that much logic into one line of a query. Build a custom function in a Module.

The query becomes this:

Selected: getSelected([Rtrd_EdrDate], [Tret_DateFrom], [Rtrd_Status],[Box5])

And then your function looks like this:


Code:
Public Function getSelected(EdrDate As Date, DateFrom As Date, Rtrd_Status As String, Box5 As Long) AS String

Dim ret as String
ret="Error"
' return value, will be set below

' put all your logic in however many lines it takes here

getSelected=ret

End Function
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:30
Joined
Feb 19, 2002
Messages
43,233
You have three different, independent conditions all of which might be true at the same time. The IIf() conditions you coded will return the LAST true value from the OR's but the Switch() suggestion will return the FIRST. Which do you want? What do you want if all are false? If you can't define what you want, no one can help you to code it.
 

Users who are viewing this thread

Top Bottom