T
Tim Long
Hello, I am trying to run a query that updates a value in one table based on
the sum of values in another table and I don’t understand what I’m doing
wrong.
Below is a simplified version of what I’ve got... I have a query that gives
me the total of the salaries in the employees table (qryEmployeeCosts) and I
want to use the result from that query to update the Salaries field in the
Costs table using an update query (qryUpdateCosts). What I’m trying to do
seems simple enough but it doesn’t work and I don’t know what elementary
error(s) I’m making. I have shown two versions of qryUpdateCosts and the
result I get with each. Any help would be much appreciated.
EMPLOYEES
EmployeeID Employee Name Salary Year
1 John Smith 30000 2005
2 Sarah Jones 40000 2005
3 Jack Brown 50000 2005
COSTS
Salaries
qryEmployeeCosts
SELECT Sum([Salary]) AS SalaryCosts
FROM Employees;
Result: 120000
qryUpdateCosts
UPDATE Costs SET Costs.Salaries = [qryEmployeeCosts].[SalaryCosts];
Result: Enter Parameter Value.. qryEmployeeCosts.SalaryCosts
Or
UPDATE Costs, Employees SET Costs.Salaries = Sum([Employees].[Salary]);
Result: You tried to execute a query that does not include the specified
expression ‘Salaries’ as part of an aggregate function.
In my real tables, I have to specify a date range (for example, sum of
salaries where year = 2005 etc) and I didn't know how to sum the salaries for
a date range in one table and use that figure to update the Salaries field in
the Costs table all in the same query (ie an update query that also sums
values in another table), so decided to use two separate queries.
Many thanks in advance
Tim Long
the sum of values in another table and I don’t understand what I’m doing
wrong.
Below is a simplified version of what I’ve got... I have a query that gives
me the total of the salaries in the employees table (qryEmployeeCosts) and I
want to use the result from that query to update the Salaries field in the
Costs table using an update query (qryUpdateCosts). What I’m trying to do
seems simple enough but it doesn’t work and I don’t know what elementary
error(s) I’m making. I have shown two versions of qryUpdateCosts and the
result I get with each. Any help would be much appreciated.
EMPLOYEES
EmployeeID Employee Name Salary Year
1 John Smith 30000 2005
2 Sarah Jones 40000 2005
3 Jack Brown 50000 2005
COSTS
Salaries
qryEmployeeCosts
SELECT Sum([Salary]) AS SalaryCosts
FROM Employees;
Result: 120000
qryUpdateCosts
UPDATE Costs SET Costs.Salaries = [qryEmployeeCosts].[SalaryCosts];
Result: Enter Parameter Value.. qryEmployeeCosts.SalaryCosts
Or
UPDATE Costs, Employees SET Costs.Salaries = Sum([Employees].[Salary]);
Result: You tried to execute a query that does not include the specified
expression ‘Salaries’ as part of an aggregate function.
In my real tables, I have to specify a date range (for example, sum of
salaries where year = 2005 etc) and I didn't know how to sum the salaries for
a date range in one table and use that figure to update the Salaries field in
the Costs table all in the same query (ie an update query that also sums
values in another table), so decided to use two separate queries.
Many thanks in advance
Tim Long