can you post your table structure?
If I were doing this I would have a table structure something like:
Courses
CourseID (autonumber)
CourseName
CourseCostPerClient
Budget
BudgetID (autonumber)
CourseID (number from courses table)
BudgetAmt (though it appears you're using different costs for the same course for different contracts)
BudgetYear (since I'm assuming you have an annual budget for each)
CourseHistory
HistoryID (autonumber)
CourseID (number from courses)
TraineeCount (number)
CourseDate (date/time if they are one day courses)
It doesn't appear to be important who your trainees are, you are just after a total count in your calculation. Next it appears from your query that you want the deductions to happen by COURSEID not by the client and you want a running sum where the amount remaining on the budget is the sum of all prior classes subtracted from the budget amount and you want that amount displayed on each row.
You can do this in a query but it's extremely clunk, particularly if you start to get a lot of data in these fields. If I'm right, and please correct me if I'm not you want your first two rows of your query to appear like this:
Code:
Cont Course Train CostCoure Budget Spent Remaining
SB1 Sm Bus 2 100 100000 200 99800
SB4 Sm Bus 2 200 100000 400 99400
if this is actually what you want does it have to be in a query or can you show it on a report and it will be acceptable?