Thanks a lot for your help. However, the formula gives me a total
of all dollar amount in the table - It doesn't give me the total
of an employee that I am search for. Can you please help me with this also?
If it is returning all the dollar amounts then the problem must be in the criteria you are passing.
The Dsum function accepts these values
DSum(expr, domain[, criteria])
if I pass
dsum("fieldname","Tablename" then it will return all the totals from the field
but if I pass it with criteria then it limits the data to whatever I pass. It is like the where statement in a query but with out the where in front
dsum("field","Table", "custid = 123"
then it will only sum all the fields where custid = 123
I can use it to pass several criteria.
what you want to pass is the employees name or id and because you want year to date you only want fields dates with this year in it. Thus year(datefield) = 2002 may be what you want.
If that is not clear enough you could try posting the statement you are using as well as the field names that are available.
I have a main form called "Employee" and a subform called "Payroll".
I need to search on an employee, and it may show any of his/her year of date.
However, I need to always have a field that shows a total amount of the current
year for that selected employee. Below is the code I have so far, but somehow
it doesn't filter out the current year nor the selected employee.
=dsum("Amount","[Payroll]","employeeid = & me!employeeid & " and year(date) = year(date))
look at the criteria you passed
the first problem is
"employeeid = & me!employeeid & "
What you are doing here is building a string to pass.
The way it is written is it is looking for an employeeid that = & me!employeeid &
I'm sure there are none that match that.
the first string neeeds to look more like
"employeeid = " & me!employeeid
the nest problem is what is the name of your field that contains the date of the amount. Is it date? if so you need to change that. Date() is a function access uses to return todays date. You can overcome that by having it read as a field
"year(payroll.date) = 2002"
combined it looks like this
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.