Adding "If Statement" with DSum

J

judyb

I am currently working with a database that needs a small adjustment to the
following code:

=DSum("[WeeksService]","Service Record Query","[EmployeeID] = " &
[EmployeeID] & " And [DepartmentName] = Current_Department_Name")


This code works to give me the sum of all Weeks Service where the Department
Name is equal to the Current Department Name and I want to keep that code.
In addition to that code though, I need to add, I'm guessing, an "IF
Statement" that will provide me with the sum of ALL Weeks Service of ALL
Department Name IF the Current Department Name is equal to "Reserves".

Example:
Department Name Weeks Service
Millwright 35 weeks
Pipefitter 10 weeks
Millwright (Current Deptment Name) 3 weeks

The existing code adds all the Weeks Service where the Department Name is
equal to the Current Department Name (Millwright) for a total of 38.

In the same example, if the Current Department Name were "Reserves", I need
code that will add ALL of the Weeks Service of ALL Department Name to give me
a total of 48.

I hope this makes sense. In short, I need to keep the existing code,
but need it to sum the Weeks Service slightly different IF the Current
Department Name is equal to "Reserves". Can both of these functions be done
in one field? Thanks in advance!
 
J

John W. Vinson

I am currently working with a database that needs a small adjustment to the
following code:

=DSum("[WeeksService]","Service Record Query","[EmployeeID] = " &
[EmployeeID] & " And [DepartmentName] = Current_Department_Name")


This code works to give me the sum of all Weeks Service where the Department
Name is equal to the Current Department Name and I want to keep that code.
In addition to that code though, I need to add, I'm guessing, an "IF
Statement" that will provide me with the sum of ALL Weeks Service of ALL
Department Name IF the Current Department Name is equal to "Reserves".

Example:
Department Name Weeks Service
Millwright 35 weeks
Pipefitter 10 weeks
Millwright (Current Deptment Name) 3 weeks

The existing code adds all the Weeks Service where the Department Name is
equal to the Current Department Name (Millwright) for a total of 38.

In the same example, if the Current Department Name were "Reserves", I need
code that will add ALL of the Weeks Service of ALL Department Name to give me
a total of 48.

I hope this makes sense. In short, I need to keep the existing code,
but need it to sum the Weeks Service slightly different IF the Current
Department Name is equal to "Reserves". Can both of these functions be done
in one field? Thanks in advance!

Did none of the four answers you've gotten the past couple of days help?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top