problem with IIF expression in query criteria containing OR condit

D

Dick Minter

The query shown below returns no records. The criteria entered direcly
without the iif performs as intended, e.g. '[forms].[fmChkList].[cbSeu] OR 1'
works if entered without the IIF expression, but as the value returned by the
iif finds no records. Note: The appostrophes in my example are for
emphasis; the values are integers.

SELECT Sources.Name, Sources.SourceID, SourceStatus.Description AS Status,
Sources.Payment_required, Market.SEUno
FROM Market INNER JOIN (SourceStatus INNER JOIN Sources ON
SourceStatus.Status = Sources.Status) ON Market.SEUno = Sources.SEU
WHERE
(((Market.SEUno)=IIf([forms].[fmChkList].[cbseu]=1,[market].[seuno],([Market].[SEUno])=[forms].[fmChkList].[cbseu] Or ([Market].[SEUno])=1)))
ORDER BY Sources.Name;

I've considered defiing and running a sql statement in the form code where
the correct criteria can be set as a string, but why doesn't the above
statement work?

DM
 
M

Michel Walsh

Depends on what you want to do really, but I suspect your intention is :

WHERE ( Market.SEUno = IIf(forms.fmChkList.cbseu=1, market.seuno,
Market.SEUno=forms.fmChkList.cbseu) )
Or ( Market.SEUno =1 )


Hoping it may help,
Vanderghast, Access MVP
 
J

Jerry Whittle

You can't have the Or statement in the third argument of the IIf. Would
moving the "Or ([Market].[SEUno])=1" behind the IIf statement return the
right records?
 
D

Dick Minter

You got me on the right track. It works when I remove 'market.SEUno=' from
the expression, i.e.

WHERE ( Market.SEUno = IIf(forms.fmChkList.cbseu=1, market.seuno,
forms.fmChkList.cbseu) ) Or ( Market.SEUno =1 ). Otherwise the query
returned only seuno = 1.

DM

Michel Walsh said:
Depends on what you want to do really, but I suspect your intention is :

WHERE ( Market.SEUno = IIf(forms.fmChkList.cbseu=1, market.seuno,
Market.SEUno=forms.fmChkList.cbseu) )
Or ( Market.SEUno =1 )


Hoping it may help,
Vanderghast, Access MVP


Dick Minter said:
The query shown below returns no records. The criteria entered direcly
without the iif performs as intended, e.g. '[forms].[fmChkList].[cbSeu] OR
1'
works if entered without the IIF expression, but as the value returned by
the
iif finds no records. Note: The appostrophes in my example are for
emphasis; the values are integers.

SELECT Sources.Name, Sources.SourceID, SourceStatus.Description AS Status,
Sources.Payment_required, Market.SEUno
FROM Market INNER JOIN (SourceStatus INNER JOIN Sources ON
SourceStatus.Status = Sources.Status) ON Market.SEUno = Sources.SEU
WHERE
(((Market.SEUno)=IIf([forms].[fmChkList].[cbseu]=1,[market].[seuno],([Market].[SEUno])=[forms].[fmChkList].[cbseu]
Or ([Market].[SEUno])=1)))
ORDER BY Sources.Name;

I've considered defiing and running a sql statement in the form code where
the correct criteria can be set as a string, but why doesn't the above
statement work?

DM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top