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  

Changing existing code to add "IF Statement"



 
 
Thread Tools Display Modes
  #1  
Old March 10th, 2010, 12:21 PM posted to microsoft.public.access
JudyB
external usenet poster
 
Posts: 46
Default Changing existing code to add "IF Statement"

I am currently using a database that is working well. However, I have
discovered that I need to make a slight change so that one of the fields
calculates differently based on the data used in another field. This is the
existing code:

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

I would like to have the code add ALL of the weeks service IF the Current
Department Name is equal to "Reserves". Can anyone provide help? Thanks in
advance.

--
Judy
  #2  
Old March 10th, 2010, 01:38 PM posted to microsoft.public.access
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default Changing existing code to add "IF Statement"

This is aircode, but if I understand your question correctly, you need
another query to return ALL weeks instead of what it presently does. Then:

If Me.Current_Deparyment_Name = "Reserves" Then
=DSum("[WeeksService]","Service Record Query2","[EmployeeID] = " &
[EmployeeID] & " And [DepartmentName] = Current_Department_Name")
Else
=DSum("[WeeksService]","Service Record Query","[EmployeeID] = " &
[EmployeeID] & " And [DepartmentName] = Current_Department_Name")
End If

Notice a different query: "Service Record Query2" which will return all
weeks instead of specific ones.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access

"judyb" wrote in message
...
I am currently using a database that is working well. However, I have
discovered that I need to make a slight change so that one of the fields
calculates differently based on the data used in another field. This is
the
existing code:

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

I would like to have the code add ALL of the weeks service IF the Current
Department Name is equal to "Reserves". Can anyone provide help? Thanks
in
advance.

--
Judy



  #3  
Old March 10th, 2010, 02:38 PM posted to microsoft.public.access
Rebecca Brayer
external usenet poster
 
Posts: 1
Default Changing existing code to add "IF Statement"

ztuiolökujzhjklrdmncfgvbvjh ghhgfdghtgcfdf

"judyb" schrieb im Newsbeitrag
...
I am currently using a database that is working well. However, I have
discovered that I need to make a slight change so that one of the fields
calculates differently based on the data used in another field. This is
the
existing code:

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

I would like to have the code add ALL of the weeks service IF the Current
Department Name is equal to "Reserves". Can anyone provide help? Thanks
in
advance.

--
Judy


  #4  
Old March 10th, 2010, 08:20 PM posted to microsoft.public.access
JudyB
external usenet poster
 
Posts: 46
Default Changing existing code to add "IF Statement"

Arvin,

Thanks for responding. After rereading my post, I find that I wasn't very
clear. I'll try again. The existing code works to give me the sum of all
Weeks Service where the Department Name is equal to the Current Department
Name and I do 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 (Millwright) for a total of 38.

In the same example, if the Current Department 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 more 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". Thanks Again!


--
Judy


"Arvin Meyer [MVP]" wrote:

This is aircode, but if I understand your question correctly, you need
another query to return ALL weeks instead of what it presently does. Then:

If Me.Current_Deparyment_Name = "Reserves" Then
=DSum("[WeeksService]","Service Record Query2","[EmployeeID] = " &
[EmployeeID] & " And [DepartmentName] = Current_Department_Name")
Else
=DSum("[WeeksService]","Service Record Query","[EmployeeID] = " &
[EmployeeID] & " And [DepartmentName] = Current_Department_Name")
End If

Notice a different query: "Service Record Query2" which will return all
weeks instead of specific ones.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access

"judyb" wrote in message
...
I am currently using a database that is working well. However, I have
discovered that I need to make a slight change so that one of the fields
calculates differently based on the data used in another field. This is
the
existing code:

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

I would like to have the code add ALL of the weeks service IF the Current
Department Name is equal to "Reserves". Can anyone provide help? Thanks
in
advance.

--
Judy



.

  #5  
Old March 10th, 2010, 09:06 PM posted to microsoft.public.access
Steve[_77_]
external usenet poster
 
Posts: 1,017
Default Changing existing code to add "IF Statement"

Hi Judy,

Add an unbound textbox to the form where you get [Current_Department_Name}.
Name the textbox DepartmentNameCriteria and set its Visible property to No.
Put the following expression in its Controlsource property:
=IIF([Current_Department_Name] = "Reserves", Null,[Current_Department_Name])

Rather than use the DSum function, change your Service Record Query to a
Totals query. Click on the Sigma button (looks like a capital E) in the menu
at the top of the screen. Change Group By under WeeksService to Sum. Change
Group By under DepartName to Where. Put the following expression in the
criteria under DepartmentName:
Forms!NameOfYourForm!DepartmentNameCriteria Or
(Forms!NameOfYourFormDepartmentNameCriteria Is Null)

Steve


"judyb" wrote in message
...
I am currently using a database that is working well. However, I have
discovered that I need to make a slight change so that one of the fields
calculates differently based on the data used in another field. This is
the
existing code:

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

I would like to have the code add ALL of the weeks service IF the Current
Department Name is equal to "Reserves". Can anyone provide help? Thanks
in
advance.

--
Judy



  #6  
Old March 11th, 2010, 04:31 PM posted to microsoft.public.access
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default Changing existing code to add "IF Statement"

Yes, you just need a new query which shows ALL departments. Department Name
doesn't need to be a part of the query.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access


"judyb" wrote in message
...
Arvin,

Thanks for responding. After rereading my post, I find that I wasn't very
clear. I'll try again. The existing code works to give me the sum of all
Weeks Service where the Department Name is equal to the Current Department
Name and I do 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 (Millwright) for a total of 38.

In the same example, if the Current Department 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 more 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". Thanks Again!


--
Judy


"Arvin Meyer [MVP]" wrote:

This is aircode, but if I understand your question correctly, you need
another query to return ALL weeks instead of what it presently does.
Then:

If Me.Current_Deparyment_Name = "Reserves" Then
=DSum("[WeeksService]","Service Record Query2","[EmployeeID] = " &
[EmployeeID] & " And [DepartmentName] = Current_Department_Name")
Else
=DSum("[WeeksService]","Service Record Query","[EmployeeID] = " &
[EmployeeID] & " And [DepartmentName] = Current_Department_Name")
End If

Notice a different query: "Service Record Query2" which will return all
weeks instead of specific ones.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access

"judyb" wrote in message
...
I am currently using a database that is working well. However, I have
discovered that I need to make a slight change so that one of the
fields
calculates differently based on the data used in another field. This
is
the
existing code:

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

I would like to have the code add ALL of the weeks service IF the
Current
Department Name is equal to "Reserves". Can anyone provide help?
Thanks
in
advance.

--
Judy



.



  #7  
Old March 13th, 2010, 05:30 PM posted to microsoft.public.access
De Jager
external usenet poster
 
Posts: 393
Default Changing existing code to add "IF Statement"


"Arvin Meyer [MVP]" wrote in message
...
Yes, you just need a new query which shows ALL departments. Department
Name doesn't need to be a part of the query.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access


"judyb" wrote in message
...
Arvin,

Thanks for responding. After rereading my post, I find that I wasn't
very
clear. I'll try again. The existing code works to give me the sum of
all
Weeks Service where the Department Name is equal to the Current
Department
Name and I do 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 (Millwright) for a total of 38.

In the same example, if the Current Department 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 more 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". Thanks Again!


--
Judy


"Arvin Meyer [MVP]" wrote:

This is aircode, but if I understand your question correctly, you need
another query to return ALL weeks instead of what it presently does.
Then:

If Me.Current_Deparyment_Name = "Reserves" Then
=DSum("[WeeksService]","Service Record Query2","[EmployeeID] = " &
[EmployeeID] & " And [DepartmentName] = Current_Department_Name")
Else
=DSum("[WeeksService]","Service Record Query","[EmployeeID] = " &
[EmployeeID] & " And [DepartmentName] = Current_Department_Name")
End If

Notice a different query: "Service Record Query2" which will return all
weeks instead of specific ones.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access

"judyb" wrote in message
...
I am currently using a database that is working well. However, I have
discovered that I need to make a slight change so that one of the
fields
calculates differently based on the data used in another field. This
is
the
existing code:

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

I would like to have the code add ALL of the weeks service IF the
Current
Department Name is equal to "Reserves". Can anyone provide help?
Thanks
in
advance.

--
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 10:01 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.