From your layout, I'd say your database design isn't going to work.
You are issuing items to an employee and recording that in Table 3.
When you receive the items bacl, you are recording that in Table 4.
There are no dates and no unique identifiers on the records, so you can only either sum up what the employee gets and returns, or report all the individual transactions without knowing which one occurred when. You also have no way to tell, if the employee checked out several different sets of things, and returned several different sets of things, which set returned was the one that was short.
Also, whenever you put together your queries, if the same employee has checked out the same 10 items three times and returned them all three times, unless you are careful in your query design, instead of 30 checkouts and 30 returns, you may get 90 checkouts and 90 returns. This is probably what you are experiencing now.
Code:
tblItems
ItemId (Pri Key)
ItemDesc Text
Unit (number?)
tblEmployees
EmployeeID (Pri Key)
EmployeeName Text
tblIssues
IssueID (AutoKey)
IssueDate Date
EmployeeID FK to tblEmployees
ItemCode FK to tblItems
QtyIssued Number
tblReturns
ReturnID (AutoKey)
ReturnDate Date
EmployeeID FK to tblEmployees
Itemcode FK to tblItems
QtyRecd Number
Given the above layout, then by summing the amounts issued, then "LEFT JOINing" to the sum of amounts returned, you will get the correct answers. The query would look like this:
Code:
SELECT
T1.EmployeeID,
T1.ItemCode,
T1.QtyIssued,
NZ(T2.QtyRecd) As QtyRecd,
T1.QtyIssued - NZ(
T2.QtyRecd,
FROM
( (SELECT
T1.EmployeeID,
T1.Itemcode,
Sum(T1.QtyIssued) As QtyIssued
FROM tblIssues AS T1
GROUP BY
T1.EmployeeID,
T1.Itemcode
)
LEFT JOIN
(SELECT
T2.EmployeeID,
T2.Itemcode,
Sum(T2.QtyRecd) As QtyRecd
FROM tblReturns AS T2
GROUP BY
T2.EmployeeID,
T2.Itemcode
)
ON T1.EmployeeID = T2.EmployeeID
AND T1.Itemcode = T2.Itemcode
);
The Dates and unique record IDs I added for the issued and returned tables are to allow different kinds of analysis later. For example, if a person has not returned all items they checked out, you will be able to determine on what return date the amount returned was not all that was checked out at that time.
This table and query design assumes that no employee will ever return an item they have not checked out. That's a procedural situation that you may want to consider. If it is possible that an employee may check in an item that another employee had checked out, then it would be wise to combine tables 3 and 4 and include a transaction type to determine what happened (checkin, checkout). This way, the query can become far simpler.