Solved

Update table 1 and get data table 2

Posted on 2012-12-27
5
306 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

809 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