Solved Small error in Totals query (1 Viewer)

nashaz

Member
Local time
Today, 10:38
Joined
Mar 24, 2023
Messages
111
Hi

I have a very basic issue with the total query which is doing my head in. Don't think I have had this issue before. I have the following query which works just fine as standard non-total query.

1710333355344.png


When I press Total and do the following, I get an error message saying 'enter parametric value' and gives me the error for field name 'expireson'.

1710333445298.png


However, when I click OK, the output works fine. So how do I get rid of this?

Thanks
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:38
Joined
Sep 21, 2011
Messages
14,301
Why can't you use Max instead of Expression?
 

nashaz

Member
Local time
Today, 10:38
Joined
Mar 24, 2023
Messages
111
Why can't you use Max instead of Expression?


When I select Max, it gives the same error, as seen below:

1710334830859.png


However, Access changes this to Expression itself when I save and close it. If I change it back to Max, I am getting following error:

1710334918730.png
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:38
Joined
Sep 21, 2011
Messages
14,301
No, you remove the Max from the first line. :(
 

Minty

AWF VIP
Local time
Today, 10:38
Joined
Jul 26, 2013
Messages
10,371
I don't think Access will allow you to refer to an Aliased aggregate function or expression in the same query it was derived from.

You could try referring to the calculation itself in the grouping:

Group By Max(CertificationDate - ValidFrom)

But I don't know if the query designer will let you do that, you might need to simply write the SQL query and save it.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:38
Joined
Feb 28, 2001
Messages
27,186
Taking this step-by-step, the presence of an "Enter Parameter" input box says that the "ExpiresOn" item doesn't exist or can't be found. In this case, I think the third reason is "can't be computed" (in that exact situation.)

Since the query appears to be a JOIN of three tables, and the expression for ExpiresOn comes from two different contributing tables, PERHAPS the problem is that you need to qualify the contributors. However, the aggregate of an expression here gives me pause. I'm not sure you can do this in a single query, but you CAN do a "divide and conquer" by doing the JOINs and simple expressions FIRST in a query and THEN do the GROUP BY and Aggregate functions separately.

I agree with Minty... Build an SQL query similar to this, call it ExpDatQry: (Meaning EXPression DATe QueRY)

Code:
SELECT EXC.EmployeeID AS EmpID, 
    EXC.DeliverID AS DlvrID, 
    CDT.CourseID AS CrsID, 
    EXC.CertificationDate AS CertDate, 
    (EXC.CertificationDate+ CNT.ValidFor) AS ExpiresOn, 
    (EXC.CertificationDate+ CNT.ValidFor - Date() ) AS DaysLeft
FROM ( EmployeeXCourse_JT as EXC INNER JOIN CourseDeliveryT as CDT ON EXC.DeliverID = CDT.DeliverID ) 
    INNER JOIN CourseNameT AS CNT ON CDT.CourseID = CNT.CourseID;

I gave EVERY FIELD an alias name so that the second query would be trivial to write.

Now do a query of a query:
Code:
SELECT EmpID, DlvrID, CrsID, DaysLeft, MAX( CertDate ), MAX( ExpiresOn)
FROM ExpDatQry
Group By EmpID, DlvrID, CrsID, DaysLeft
 

nashaz

Member
Local time
Today, 10:38
Joined
Mar 24, 2023
Messages
111
@Minty and @Doc Thank you for your inputs. Based on both your feedbacks, what I understood is that the totalling needs to happen in a separate query. I have done the following and it works just as I needed it (although its not as sophisticated a solution as what the Doc suggested). Thank you very much :)

1710340190084.png
 

Users who are viewing this thread

Top Bottom