Solved

Update table 1 and get data table 2

Posted on 2012-12-27
5
308 Views
Last Modified: 2012-12-28
Hi Experts,
I am trying to develop a Emp App for a small firm. I am using two table for Loan, detail as follows:

Table 1 Emp_Loan in which loan availed
Table 2 Emp_Loan_Deduction in which monthly loan deduction logged

I need to update table 1 when it is access by user either through report or form. like this, please help to do so.

Update Emp_Loan (Emp_Loan.LDeducted=Sum(Emp_Loan_Deducted .DAmount)
FROM Emp_Loan_Deducted Join Emp_Loan on Emp_Loan_Deducted.EmpID=Emp_Loan.EMPID
Group by Emp_Loan_Deducted.EmpID
HDP.accdb
0
Comment
Question by:Mehram
5 Comments
 
LVL 39

Expert Comment

by:appari
ID: 38723007
try this

Update A
Set LDeducted=DAmount_Sum
FROM Emp_Loan A Join
( Select EmpID, Sum(DAmount) DAmount_Sum From Emp_Loan_Deducted  
Group by Emp_Loan_Deducted.EmpID) B
on A.EmpID=B.EMPID
0
 

Author Comment

by:Mehram
ID: 38723030
Where I need to past it, can you edit please in my mdf
0
 
LVL 17

Expert Comment

by:k_murli_krishna
ID: 38723064
UPDATE Emp_Loan el
SET el.LDeducted = (SELECT SUM(eld.DAmount)
                                FROM Emp_Loan_Deducted eld
                                WHERE eld.EmpID=el.EMPID
                                GROUP BY eld.EmpID);
0
 

Author Comment

by:Mehram
ID: 38723077
Sir, Where I need to past it to work, can you edit please in my mdf
0
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 38723104
Just based on your posted query, it looks like what you should have is...

Update Emp_Loan  Set LDeducted=DSum("[DAmount]", "[Emp_Loan_Deducted]", "EmpID=" & Emp_Loan.EMPID)

This assumes EMPID is a number field.

The query has no specific reference to any form or report but you can run it anywhere you like.  

You cannot create an update query in Access that has a Group By expression  or any aggregate function Sum/Count/Avg etc; so the previous responses will not work.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

685 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