Using and "IF" statement

J

judyb

I am working with a database that uses the following code to sum the weeks
service that an employee works in a given department:

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

The code is working fine. However, I have discovered that I need to add
some type of "IF" statement so that if the Current Department Name is equal
to "Reserves", that it will sum all Departments (not just the Current
Department Name). Thanks in advance for your help.
 
S

Stefan Hoffmann

hi Judy,

=DSum("[WeeksService]","Service Record
Query","[EmployeeID]="&[EmployeeID]&"And[DepartmentName]=Current_Department_Name")
What is 'Current_Department_Name'?
The code is working fine.
Hmm, I'm quite sure, that it should throw an error as there are some
spaces missing.


mfG
--> stefan <--
 
J

John W. Vinson

I am working with a database that uses the following code to sum the weeks
service that an employee works in a given department:

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

The code is working fine. However, I have discovered that I need to add
some type of "IF" statement so that if the Current Department Name is equal
to "Reserves", that it will sum all Departments (not just the Current
Department Name). Thanks in advance for your help.

Use an OR in your criterion (fixed up somewhat for readability and accuracy):

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

This assumes that [Current_Department_Name] is in fact a field in the Service
Record Query. If not, please explain where and what it is.
 
J

jhall2microsoft.com

judyb said:
I am working with a database that uses the following code to sum the weeks
service that an employee works in a given department:

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

The code is working fine. However, I have discovered that I need to add
some type of "IF" statement so that if the Current Department Name is
equal
to "Reserves", that it will sum all Departments (not just the Current
Department Name). Thanks in advance for your help.
 
J

jhall2microsoft.com

judyb said:
I am working with a database that uses the following code to sum the weeks
service that an employee works in a given department:

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

The code is working fine. However, I have discovered that I need to add
some type of "IF" statement so that if the Current Department Name is
equal
to "Reserves", that it will sum all Departments (not just the Current
Department Name). Thanks in advance for your help.
 
D

De Jager

judyb said:
I am working with a database that uses the following code to sum the weeks
service that an employee works in a given department:

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

The code is working fine. However, I have discovered that I need to add
some type of "IF" statement so that if the Current Department Name is
equal
to "Reserves", that it will sum all Departments (not just the Current
Department Name). Thanks in advance for your help.
 
J

jhall2microsoft.com

jhall2microsoft.com said:
judyb said:
I am working with a database that uses the following code to sum the weeks
service that an employee works in a given department:

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

The code is working fine. However, I have discovered that I need to add
some type of "IF" statement so that if the Current Department Name is
equal
to "Reserves", that it will sum all Departments (not just the Current
Department Name). Thanks in advance for your 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