A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

IIf Statement in Query Criteria



 
 
Thread Tools Display Modes
  #1  
Old December 11th, 2009, 01:08 AM posted to microsoft.public.access.queries
AccessIM
external usenet poster
 
Posts: 81
Default IIf Statement in Query Criteria

I have the following code in a query:

SELECT qryPointsWithDropOffDates.EMPLOYEEID, qryPointsWithDropOffDates.SSN,
qryPointsWithDropOffDates.NAME, qryDisciplineNoticesReprint.LASTINCIDENTDATE,
qryPointsWithDropOffDates.INCIDENTDATE, qryPointsWithDropOffDates.TYPESHORT,
qryPointsWithDropOffDates.POINTVALUE
FROM qryDisciplineNoticesReprint INNER JOIN qryPointsWithDropOffDates ON
qryDisciplineNoticesReprint.SSN=qryPointsWithDropO ffDates.SSN
WHERE (((qryPointsWithDropOffDates.INCIDENTDATE) Between
[qryDisciplineNoticesReprint.CALCDATE] And
[qryDisciplineNoticesReprint.LASTINCIDENTDATE]) AND
((qryPointsWithDropOffDates.POINTVALUE]0))
ORDER BY qryPointsWithDropOffDates.EMPLOYEEID,
qryPointsWithDropOffDates.INCIDENTDATE;

This works fine in most circumstances. However, I did fine a loop hole I
need to fix. If the field
[qryDisciplineNoticesReprint.DISCIPLINE]="ATTENDANCE INFORMATION FORM", I
need to change the between statement to read "Between
[qryDisciplineNoticesReprint.CALCDATE] And
[qryDisciplineNoticesReprint.DISCIPLINEDATE]).

The code I am trying looks like this:

SELECT qryPointsWithDropOffDates.EMPLOYEEID, qryPointsWithDropOffDates.SSN,
qryPointsWithDropOffDates.NAME, qryDisciplineNoticesReprint.LASTINCIDENTDATE,
qryPointsWithDropOffDates.INCIDENTDATE, qryPointsWithDropOffDates.TYPESHORT,
qryPointsWithDropOffDates.POINTVALUE
FROM qryDisciplineNoticesReprint INNER JOIN qryPointsWithDropOffDates ON
qryDisciplineNoticesReprint.SSN=qryPointsWithDropO ffDates.SSN
WHERE
(((qryPointsWithDropOffDates.INCIDENTDATE)=IIf([qryDisciplineNoticesReprint.DISCIPLINE]="ATTENDANCE
INFORMATION FORM", (qryPointsWithDropOffDates.INCIDENTDATE] Between
[qryDisciplineNoticesReprint.CALCDATE] And
[qryDisciplineNoticesReprint.DISCIPLINEDATE]),(qryPointsWithDropOffDates.INCIDENTDATE)
Between [qryDisciplineNoticesReprint.CALCDATE] And
[qryDisciplineNoticesReprint.LASTINCIDENTDATE])) AND
((qryPointsWithDropOffDates.POINTVALUE]0))
ORDER BY qryPointsWithDropOffDates.EMPLOYEEID,
qryPointsWithDropOffDates.INCIDENTDATE;

With the added IIf statement in the criteria, the query returns no records.
It should return 9 records.

Can someone tell me what I am doing wrong int he code above? Thank you in
advance.
  #2  
Old December 11th, 2009, 05:48 AM posted to microsoft.public.access.queries
Duane Hookom
external usenet poster
 
Posts: 7,177
Default IIf Statement in Query Criteria

You can't put the Betwen inside the IIf(). Try a WHERE CLAUSE of
WHERE INCIDENTDATE Between CALCDATE And
IIF(DISCIPLINE]="ATTENDANCE INFORMATION FORM",
DISCIPLINEDATE,LASTINCIDENTDATE)
AND POINTVALUE0

--
Duane Hookom
Microsoft Access MVP


"AccessIM" wrote:

I have the following code in a query:

SELECT qryPointsWithDropOffDates.EMPLOYEEID, qryPointsWithDropOffDates.SSN,
qryPointsWithDropOffDates.NAME, qryDisciplineNoticesReprint.LASTINCIDENTDATE,
qryPointsWithDropOffDates.INCIDENTDATE, qryPointsWithDropOffDates.TYPESHORT,
qryPointsWithDropOffDates.POINTVALUE
FROM qryDisciplineNoticesReprint INNER JOIN qryPointsWithDropOffDates ON
qryDisciplineNoticesReprint.SSN=qryPointsWithDropO ffDates.SSN
WHERE (((qryPointsWithDropOffDates.INCIDENTDATE) Between
[qryDisciplineNoticesReprint.CALCDATE] And
[qryDisciplineNoticesReprint.LASTINCIDENTDATE]) AND
((qryPointsWithDropOffDates.POINTVALUE]0))
ORDER BY qryPointsWithDropOffDates.EMPLOYEEID,
qryPointsWithDropOffDates.INCIDENTDATE;

This works fine in most circumstances. However, I did fine a loop hole I
need to fix. If the field
[qryDisciplineNoticesReprint.DISCIPLINE]="ATTENDANCE INFORMATION FORM", I
need to change the between statement to read "Between
[qryDisciplineNoticesReprint.CALCDATE] And
[qryDisciplineNoticesReprint.DISCIPLINEDATE]).

The code I am trying looks like this:

SELECT qryPointsWithDropOffDates.EMPLOYEEID, qryPointsWithDropOffDates.SSN,
qryPointsWithDropOffDates.NAME, qryDisciplineNoticesReprint.LASTINCIDENTDATE,
qryPointsWithDropOffDates.INCIDENTDATE, qryPointsWithDropOffDates.TYPESHORT,
qryPointsWithDropOffDates.POINTVALUE
FROM qryDisciplineNoticesReprint INNER JOIN qryPointsWithDropOffDates ON
qryDisciplineNoticesReprint.SSN=qryPointsWithDropO ffDates.SSN
WHERE
(((qryPointsWithDropOffDates.INCIDENTDATE)=IIf([qryDisciplineNoticesReprint.DISCIPLINE]="ATTENDANCE
INFORMATION FORM", (qryPointsWithDropOffDates.INCIDENTDATE] Between
[qryDisciplineNoticesReprint.CALCDATE] And
[qryDisciplineNoticesReprint.DISCIPLINEDATE]),(qryPointsWithDropOffDates.INCIDENTDATE)
Between [qryDisciplineNoticesReprint.CALCDATE] And
[qryDisciplineNoticesReprint.LASTINCIDENTDATE])) AND
((qryPointsWithDropOffDates.POINTVALUE]0))
ORDER BY qryPointsWithDropOffDates.EMPLOYEEID,
qryPointsWithDropOffDates.INCIDENTDATE;

With the added IIf statement in the criteria, the query returns no records.
It should return 9 records.

Can someone tell me what I am doing wrong int he code above? Thank you in
advance.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:04 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.