Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I???

Status
Not open for further replies.

Lhuffst

Programmer
Jun 23, 2003
503
US
I have a query with a set of criteria. It's retrieving my data fine but now I have to take that data and sort it for the report. Not sure the best weay to handle it.

Here are the criteria.

query:

Prompted fields: ReportStart: [enter start date] ReportEnd: [enter end date]
Field: Effective Date:
Criteria:
1. <=[Report End Date] and >= [report start date]​
2. <=[Report End Date] and >= [report start date]​
3. <=[Report End Date] and >= [report start date]​
4. <=[Report End Date] and >= [report start date]​

Field: Retiredate
Criteria:
1. >[Report start Date]​
2. isnull​
3. <=[Report End Date] and >= [report start date]​
4. >[Report End Date]​

Field: left(PermitNo, 2) (WH or not WH)

I couldn't figure out how to set this note up as a table effect. the criteria lines should match up and
Lines 1 and 3 should be considered retired
Lines 2 and 4 should be considered active

What I need for a sort is:

If the left(PermitNo, 2) is WH and active, then group1
if the left(PermitNo, 2) is not WH and active then group 2
if the left(PermitNo, 2) is WH and retired, then group 3
if the left(PermitNo, 2) is not WH and retired the Group 4

Code:
on the report group header I've tried
=IIf(Left([PermitNo],2)="WH" And Nz([Retiredate],#12/31/2050#)>[reportend],"1",IIf(Left([PermitNo],2)<>"WH" And Nz([RetireDate],#12/31/2050#)>[ReportEnd],"2",IIf(Left([PermitNo],2)="WH" And Nz([RetireDate],#12/31/2050#)<=[ReportEnd],"3","4")))  [highlight #3465A4]the Nz doesn't return any errors or records[/highlight][highlight #FFFFFF][/highlight]
 

=IIF(Left([PermitNo],2)="WH" and sortGrp = "A", "1", IIF(Left([PermitNo],2)<>"WH" and sortGrp = "A", "2", iif(Left([PermitNo],2) <> "WH" and SortGrp = "A", "3", "4"))) [highlight #3465A4]everything goes in active even though sortgrp has them as retired[/highlight]

in the query I made another column
SortGrp: IIf(([effectivedate]<=[report end date] And [effectivedate]>=[report start date]) And [retiredate]>[report start date],"R",IIf(([effectivedate]<=[report end date] And [effectivedate]>=[report Start Date]) And ([retiredate]>=[Report Start Date] And [retiredate]<=[Report End Date]),"R",IIf(([effectivedate]<=[report end date] And [effectivedate]>=[report start date]) And IsNull([retiredate]),"A",IIf(([effectivedate]<=[report end date] And [effectivedate]>=[report start date]) And [retiredate]>[report end date],"A","oops"))))  Everything comes out retired
on the report group header, if I spell everything out, then I run into to many characters errors
 
If I follow you should have a complicated nested series of IIF to get to your groups and return field. Then sort by that column in your report.
 
I ended up putting the code in the query.

qry columns:
[Enter Report Start Date]
[Enter Report End Date]

SrtGrp: SortGrp: IIf([SortGrp2]="Active WH",1,IIf([SortGrp2]="Active Other",2,IIf([SortGrp2]="Retired WH",3,4)))

SrtGrp2: SortGrp2: Switch(Mid([t_PermitAccounts].[PermitNo],1,2)='WH' And ([t_HaulerVehicles].[EffectiveDate] Between [Report Start Date] And [Report End Date]) And ([t_HaulerVehicles].[RetireDate]<=[Report End Date]),'Retired WH',Mid([t_PermitAccounts].[PermitNo],1,2)<>'WH' And ([t_HaulerVehicles].[EffectiveDate] Between [Report Start Date] And [Report End Date]) And ([t_HaulerVehicles].[RetireDate]<=[Report End Date]),'Retired Other',Mid([t_PermitAccounts].[PermitNo],1,2)='WH' And ([t_HaulerVehicles].[EffectiveDate] Between [Report Start Date] And [Report End Date]) And ([t_HaulerVehicles].[RetireDate]>[Report End Date]),'Active WH',Mid([t_PermitAccounts].[PermitNo],1,2)<>'WH' And ([t_HaulerVehicles].[EffectiveDate] Between [Report Start Date] And [Report End Date]) And ([t_HaulerVehicles].[RetireDate]>[Report End Date]),'Active Other')

Then I used SrtGrp as the report group header. In the Group Header Area I put a label: =IIf([SortGrp]=1,"ADDITIONS TO PERMITTED WASTE HAULERS",IIf([SortGrp]=2,"ADDITIONS TO BUSES/OTHER",IIf([SortGrp]=3,"RETIRED PERMITTED WASTE HAULERS","RETIRED BUSES/OTHER")))

Works very nice. Thanks for all the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top