Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subtract last record from current record in query

Status
Not open for further replies.

HalfMoon2

IS-IT--Management
Apr 25, 2006
4
JM
I am trying to calculate the taxes due this week in a query. Here is the scenario - I have a table named "Payroll Data Entry" with field including "PayID" (primary key), "PayDate", "TaxToDate", etc. I have created a query named Payroll with simple calculation to get "TaxToDate" totals. Based on the last pay date for an employee, I want to subtract the previous 'TaxToDate' record for an employee from the current 'TaxToDate' record for that employee and return that value in a field name "TaxThisWeek". This is what I have in my "TaxThisWeek" field in query:

TaxThisWeek:
(SELECT PayID, PayDate,TaxToDate,
(SELECT TOP 1 Dupe.TaxToDate
FROM Payroll Data Entry AS Dupe
WHERE Dupe.WeekNum = MeterReading.WeekNum
AND Dupe.PayDate < MeterReading.PayDate
ORDER BY Dupe.PayDate DESC, Dupe.PayID) AS PriorValue
FROM Payroll Data Entry; )

However, I continue to get a Run-time (3075) Error code, what am I missing or not doing?

N.B. An employee might not get paid on some pay date, so pay date may not be in number sequence. I have created WeekNum to get the week number the PayDate falls in.

Thanks in advance.
Mario



 
I'm guessing MeterReading is a copy/paste error from a sample you got? Also, because of the inadvisable spaces, this would have to be bracketed:

[Payroll Data Entry]

Fix those and let's see where we're at.

Paul
MS Access MVP 2007/2008
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top