Purpose: To track the balance of funds by account (Encumbrance – Expense = Balance).
Function: I have to make a report that groups the records (employees) by account number* from two tables (tblEncumbrance & tblExpense).
*Issue1: The account number consists of several (6) fields: Fund, Organization, Account, Program, & Activity. However, not all the above account fields have data (often times the activity is blank and sometimes the program is blank, but essentially any one of the 6 fields could be blank – employee error, but it is not yet a forced required field in the database).
Acct string example: Fund - Org - Acct - Prog - Actv
T17
055
C23
50
DCE
Issue2: Sometimes there are expenses for an account (string) that does not have an encumbrance.
I have made two queries: (successfully) (I also made 2 queries that puts the below results in a new table)
- that totals the encumbrance amount by person within the Accounting string.
- that totals the expense amount by person within the Accounting string.
Now I have to make a report that lists all the employees within the account string an calculates the encumbrance – expense. It sounds simple, but I am not able to successfully do this.
Here is the code:
SELECT [tblEncumbranceTotal.Fund] & "-" & [tblEncumbranceTotal.Org] & "-" & [tblEncumbranceTotal.Account] & "-" & [tblEncumbranceTotal.ProgramCode] & "-" & [tblEncumbranceTotal.Activity] AS FOAPAL, tblEncumbranceTotal.Fund, tblEncumbranceTotal.Org, tblEncumbranceTotal.Account, tblEncumbranceTotal.ProgramCode, tblEncumbranceTotal.Activity, tblEncumbranceTotal.EmployeeName, tblEncumbranceTotal.EmployeeID, tblEncumbranceTotal.Encumbrance, tblExpenseTotal.GrossSalary, ([tblEncumbranceTotal.Encumbrance]-[GrossSalary]) AS Balance
FROM tblEncumbranceTotal INNER JOIN tblExpenseTotal ON tblEncumbranceTotal.EmployeeID = tblExpenseTotal.EmployeeID;
Here are the results:
Fund Org Account ProgramCode Activity EmployeeName EmployeeID Encumbrance GrossSalary Balance F03 020 C05 40 Doe, Jane 329520 $4,500.00 $3,920.00 $580.00 F03 020 C05 40 Doe, Jane 329520 $4,500.00 $2,512.50 $1,987.50 F03 020 C05 40 Doe, Jane 329520 $4,500.00 $8,325.42 ($3,825.42)
Here is what it SHOULD produce: (note, I put pale yellow where the fields are not necessary, but just show so you can see what table they are from: Green is encumbrance; Yellow is expense.
F03 020 C05 40 ACT2 Doe, Jane Doe, Jane 329520 329520 $4,500.00 $3,920.00 $580.00 Smith, John Smith, John 441444 441444 $2,800.00 $2,000.00 $800.00 Zulu, Fred Zulu, Fred 552555 552555 $10,950.00 $5,400.00 $5,550.00 $18,250.00 $11,320.00 $6,930.00 T17 510 C23 50 Doe, Jane Doe, Jane 329520 329520 $23,203.44 $8,325.42 $14,878.02 Zulu, Fred Zulu, Fred 552555 552555 $25,000.00 $12,500.00 $12,500.00 $48,203.44 $20,825.42 $27,378.02 T17 055 C23 50 DCE Doe, Jane 329520 $2,512.50 ($2,512.50) $0.00 $2,512.50 ($2,512.50) $66,453.44 $34,657.92 $31,795.52
Any suggestions/advice on how to achieve this?