Using and "IF" statement

  • Thread starter Thread starter judyb
  • Start date Start date
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.
 
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 <--
 
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.
 
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.
 
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.
 
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.
 
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.
 
Back
Top