Adding "IF Statement" to existing code

J

judyb

I am currently working with a database that is working well. However, I have
discovered that I need to add an "IF Statement" to change the expression so
that it adds all of the weeks service if the DepartmentName field is equal to
"Reserves". This is the existing code:

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

How do I need to change the code so that all of the weeks service will be
added together if the DepartmentName is equal to "Reserves"? Thanks in
advance for your help.

Judy
 
T

Tom van Stiphout

On Wed, 10 Mar 2010 04:17:01 -0800, judyb

I'm thinking:
=DSum("[WeeksService]","Service Record Query","[EmployeeID] = " &
[EmployeeID] & " And [DepartmentName] = 'Reserves'")
(note the single-quotes around Reserves)
but that seems so obvious you probably already tried that. What
happened?

-Tom.
Microsoft Access MVP
 
A

Al Campagna

judyb,
If EmployeeID is numeric and DepartmentName is text...

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

Couldn't test, but that should do it...
--
hth
Al Campagna
Microsoft Access MVP 2007-2009
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
A

Al Campagna

Judy...
Meant to say... here's the code with spaces between the single and
double quotes, added for clarity.
=DSum("[WeeksService]","Service Record Query","[EmployeeID] = " &
[EmployeeID] & " And [DepartmentName] = ' " & Current_Department_Name & "
' ")
Don't use them in the real code.
--
hth
Al Campagna
Microsoft Access MVP 2007-2009
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."

Al Campagna said:
judyb,
If EmployeeID is numeric and DepartmentName is text...

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

Couldn't test, but that should do it...
--
hth
Al Campagna
Microsoft Access MVP 2007-2009
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."


judyb said:
I am currently working with a database that is working well. However, I
have
discovered that I need to add an "IF Statement" to change the expression
so
that it adds all of the weeks service if the DepartmentName field is
equal to
"Reserves". This is the existing code:

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

How do I need to change the code so that all of the weeks service will be
added together if the DepartmentName is equal to "Reserves"? Thanks in
advance for your help.

Judy
 

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