Solved

In an Access 2003 application, how to resolve the error "You tried to execute a query that does not include the specified expression ... as part of an aggregate function?

Posted on 2014-02-10
2
1,871 Views
Last Modified: 2014-02-10
In an Access 2003 application, how to fix the error
"You tried to execute a query that does not include the specified expression
'IIF(tbl_SMR_OpenItems.T="E","D",tbl_SMR_OpenItems.T)' as part of an
aggregate function.

SELECT tbl_SMR_OpenItems.Bank,
          IIf(tbl_SMR_OpenItems.T="E","D",tbl_SMR_OpenItems.T) AS T,
          IIf([AgeDays]<6,"1-5",
          IIf([AgeDays]<11,"6-10",
          IIf([AgeDays]<16,"11-15",
          IIf([AgeDays]<21,"16-20",
          IIf([AgeDays]<26,"21-25",
          IIf([AgeDays]<31,"26-30",
          "31+")))))) AS AgeRange,
          Sum(tbl_SMR_OpenItems.amount) AS [$],
          Count(tbl_SMR_OpenItems.Type) AS Items
          INTO tbl_SMR_OpenItemsAgeRange
          FROM tbl_SMR_OpenItems
          GROUP BY tbl_SMR_OpenItems.Bank,
          tbl_SMR_OpenItems.T,
          IIf([AgeDays]<6,"1-5",
          IIf([AgeDays]<11,"6-10",
          IIf([AgeDays]<16,"11-15",
          IIf([AgeDays]<21,"16-20",
          IIf([AgeDays]<26,"21-25",
          IIf([AgeDays]<31,"26-30",
          "31+"))))));
0
Comment
Question by:zimmer9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39847518
You will not be able to refer to the computed field, [T], you will need to use the expression:

    IIf(tbl_SMR_OpenItems.T="E","D",tbl_SMR_OpenItems.T)

Just like you did with the expession for AgeRange

 GROUP BY tbl_SMR_OpenItems.Bank,
 IIf(tbl_SMR_OpenItems.T="E","D",tbl_SMR_OpenItems.T),
 IIf([AgeDays]<6,"1-5",
 IIf([AgeDays]<11,"6-10",
 IIf([AgeDays]<16,"11-15",
 IIf([AgeDays]<21,"16-20",
 IIf([AgeDays]<26,"21-25",
 IIf([AgeDays]<31,"26-30",
 "31+"))))));
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 39847546
You might also want to consider creating a table for those age ranges, something like: tbl_lst_AgeRanges (RangeGE, RangeLT, RangeText)  with values like:

RangeGE   RangeLT    RangeText
0                     6           "1-5"
6                    11          "6-10"
11                  16          "11-15"
16                  21          "16-20"
21                  26          "21-25"
26                 31           "26-30"
31                 999           "31+"

Then, in your query, you would use a non-equi join (can only be completed in the SQL view) like:

SELECT tbl_SMR_OpenItems.Bank, RangeText as AgeRange
FROM tbl_SMR_OpenItems
INNER JOIN tbl_lst_AgeRanges
ON tbl_SMR_OpenItems.[AgeDays] >= tbl_lst_AgeRanges.RangeGE
AND tbl_SMR_OpenItems.[AgeDays] < tbl_lst_AgeRanges.RangeLT

This way, you could easily change you age ranges in a table, and not have to go looking for where you did it in code or queries.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ACESS 2010 Query Criteria 23 48
MS ACCESS VBA FORMATTING 9 57
Question about Common Table Expressions 3 39
Multiple tables for a tabbed form 2 21
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question