The following query (which isn't working) works off of the MonthYear field in the table tblPayrollRecords, which is a date field (e.g., 1/1/2025). If the current month is January, it returns the GrossAvailable value for January. If it is any other month in the year, it returns the January value plus the sum of all the GrossAvailable values for the remainder of the year.
Here's the query that isn't working:
PayrollAmt2: IIf((DatePart("m",[MonthYear]))=1,
[GrossAvailable],
([GrossAvailable]+DSum("GrossAvailable","tblPayrollRecords","tblPay rollRecords.EmployeeID= “ & [EmployeeID] & “ And [MonthYear] >= #"
& DateSerial(Year(Date()),1,1) &
"# And [MonthYear] <= #"
& DateSerial(Year(Date()),DatePart("m",[MonthYear])-1,1) & "#")))
BUT, if I insert a specific EmployeeID value, as below, it works properly.
PayrollAmt2: IIf((DatePart("m",[MonthYear]))=1,
[GrossAvailable],
([GrossAvailable]+DSum("GrossAvailable","tblPayrollRecords","tblPay rollRecords.EmployeeID= 48 And [MonthYear] >= #"
& DateSerial(Year(Date()),1,1) &
"# And [MonthYear] <= #"
& DateSerial(Year(Date()),DatePart("m",[MonthYear])-1,1) & "#")))
So, I'm guessing there's something wrong in the syntax, though it's not throwing any errors.
Thanks for any help to get it working properly.