A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Using and "IF" statement



 
 
Thread Tools Display Modes
  #1  
Old March 9th, 2010, 06:09 PM posted to microsoft.public.access
JudyB
external usenet poster
 
Posts: 46
Default Using and "IF" statement

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.

--
Judy
  #2  
Old March 9th, 2010, 06:22 PM posted to microsoft.public.access
Stefan Hoffmann
external usenet poster
 
Posts: 991
Default Using and "IF" statement

hi Judy,

On 09.03.2010 19:09, judyb wrote:
=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 --
  #3  
Old March 9th, 2010, 10:28 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Using and "IF" statement

On Tue, 9 Mar 2010 10:09:01 -0800, judyb
wrote:

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.
--

John W. Vinson [MVP]
  #4  
Old March 12th, 2010, 04:35 PM posted to microsoft.public.access
jhall2microsoft.com
external usenet poster
 
Posts: 11
Default Using and "IF" statement


"judyb" wrote in message
...
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.

--
Judy


  #5  
Old March 12th, 2010, 04:35 PM posted to microsoft.public.access
jhall2microsoft.com
external usenet poster
 
Posts: 11
Default Using and "IF" statement

"judyb" wrote in message
...
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.

--
Judy


  #6  
Old March 13th, 2010, 05:33 PM posted to microsoft.public.access
De Jager
external usenet poster
 
Posts: 393
Default Using and "IF" statement


"judyb" wrote in message
...
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.

--
Judy


  #7  
Old March 16th, 2010, 09:18 PM posted to microsoft.public.access
jhall2microsoft.com
external usenet poster
 
Posts: 11
Default Using and "IF" statement


"jhall2microsoft.com" wrote in message
...
"judyb" wrote in message
...
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.

--
Judy



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:02 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.