Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
1,984 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 48

Expert Comment

by:Dale Fye
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 48

Accepted Solution

by:
Dale Fye earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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.

636 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