anil said:
I want to use OR in IIF statement as a condition in the query
'Quarterly' OR IIf([Sampler_loc].[monthID]=Month([tblnewone].[BDate])
AND WeekOfMonth2([tblnewone].[BDate])=1, 'monthly' OR
'Fortnightly','Weekly')))
But it gives me error at 'monthly' or 'Fortnightly'
Actually I need 'quarterly' or 'monthly' or 'fortnightly' for same
month and week 1
and 'quarterly' or 'weekly' for remaining weeks and same month.
You can not expect Access to run a query and reconstruct the
criteria for every record. In other words, the expressions
can ony return a value, not another expression.
You did not provide enough information for me to correct
whatever you are trying to do, but the following might be
useful if what you posted is a criteria for some field.
I suspect that most of the confusion is caused by using the
query design grid and things would be a lot clearer if you
wrote the WHERE clause in SQL view.
I think(?) you want something like:
WHERE IIf(Sampler_loc.monthID=Month(tblnewone.BDate
AND WeekOfMonth2(tblnewone.BDate)=1.
somefield IN('quarterly','monthly','fortnightly')
IIf(Sampler_loc.monthID=Month(tblnewone.BDate,
somefield IN('quarterly','monthly'),
somefield = 'quarterly'))
You can do this in the query design grid by using a
calculated field with the above expression and setting its
criteria to True.
Here is complete query
SELECT DISTINCT tblnewone.LocationName, tblnewone.SiteID,
tblnewone.SiteCode, tblnewone.SiteAddress, tblnewone.SiteType,
tblnewone.BDate, WeekofMonth2(tblnewone.Bdate) AS WeekNo,
tblWSP.Frequency, tblWSP.ParameterName, tblLocation.LocationSDWTown,
tblWSP.LabTested
FROM ((tblLocation INNER JOIN tblWSP ON tblLocation.LocationID =
tblWSP.LocationID) INNER JOIN tblnewone ON (tblWSP.Location =
tblnewone.LocationName) AND (tblWSP.SiteType = tblnewone.SiteType))
INNER JOIN sampler_Loc ON tblnewone.LocationName =
sampler_Loc.LocationName
WHERE (((tblnewone.SiteType)='S') AND ((tblWSP.Frequency)='Weekly' Or
(tblWSP.Frequency)=IIf([Sampler_loc].[monthID]=Month([tblnewone].
[BDate]) And WeekOfMonth2([tblnewone].[BDate])=1,
(tblWSP.Frequency)='monthly' Or
(tblWSP.Frequency)="fortnightly",IIf(([Sampler_loc].
[monthID]=Month([tblnewone].[BDate]) And [Sampler_loc].[monthID]=2)
And WeekOfMonth2([tblnewone].[BDate])=2 Or ([Sampler_loc].
[monthID]=Month([tblnewone].[BDate]) And [Sampler_loc].[monthID]=3)
And WeekOfMonth2([tblnewone].[BDate])=2 Or ([Sampler_loc].
[monthID]=Month([tblnewone].[BDate]) And [Sampler_loc].[monthID]=4)
And WeekOfMonth2([tblnewone].[BDate])=2,'Annually',IIf([Sampler_loc].
[monthID]=Month([tblnewone].[BDate]) And WeekOfMonth2([tblnewone].
[BDate])=3,(tblWSP.Frequency)='Quarterly' Or
(tblWSP.Frequency)="fortnightly",'Weekly')))));
Here in this query on basis on week and monthly I have to pick
parameters e.g some parameters are tested on frequency weekly,some
fortnightly , some monthly,some quarterly and some annually.
I get the problem at - tblWSP.Frequency)='monthly' Or
(tblWSP.Frequency)="fortnightly",
It gives data type mismatch in criteria expression. When I remove
fortnightly , it works fine.