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 » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Syntax for If then Conditional Statement



 
 
Thread Tools Display Modes
  #1  
Old June 27th, 2008, 03:21 PM posted to microsoft.public.access.queries
Melissa
external usenet poster
 
Posts: 409
Default Syntax for If then Conditional Statement

I'm trying to write a conditional statement in a query that gives me the
following:
If product ID = 64, 128, or 75, then the renewal rate is 1%. All other
product ID's get a renewal rate of 2%. My statement below gives me 1% for all
products, and I can't get the syntax right to give me the 2% value for all
other products. Anyone have any suggestions?

Renewal: IIf([Hoppenstein]![ProductID]="64" Or "128" Or
"75",[Hoppenstein]![Renewal]*0.01,[Hoppenstein]![Renewal]*0.02)
--
Thanks,
Melissa
  #2  
Old June 27th, 2008, 03:31 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Syntax for If then Conditional Statement

Use this ---

Renewal: IIf([Hoppenstein]![ProductID]="64" Or
[Hoppenstein]![ProductID]="128" Or
[Hoppenstein]![ProductID]="75",[Hoppenstein]![Renewal]*0.01,[Hoppenstein]![Renewal]*0.02)

If ProductID field is not text but is a number field then remove the quotes
like this --
Renewal: IIf([Hoppenstein]![ProductID]=64 Or [Hoppenstein]![ProductID]=128
Or
[Hoppenstein]![ProductID]=75,[Hoppenstein]![Renewal]*0.01,[Hoppenstein]![Renewal]*0.02)

--
KARL DEWEY
Build a little - Test a little


"Melissa" wrote:

I'm trying to write a conditional statement in a query that gives me the
following:
If product ID = 64, 128, or 75, then the renewal rate is 1%. All other
product ID's get a renewal rate of 2%. My statement below gives me 1% for all
products, and I can't get the syntax right to give me the 2% value for all
other products. Anyone have any suggestions?

Renewal: IIf([Hoppenstein]![ProductID]="64" Or "128" Or
"75",[Hoppenstein]![Renewal]*0.01,[Hoppenstein]![Renewal]*0.02)
--
Thanks,
Melissa

  #3  
Old June 27th, 2008, 03:55 PM posted to microsoft.public.access.queries
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Syntax for If then Conditional Statement

Melissa wrote:

I'm trying to write a conditional statement in a query that gives me the
following:
If product ID = 64, 128, or 75, then the renewal rate is 1%. All other
product ID's get a renewal rate of 2%. My statement below gives me 1% for all
products, and I can't get the syntax right to give me the 2% value for all
other products. Anyone have any suggestions?

Renewal: IIf([Hoppenstein]![ProductID]="64" Or "128" Or
"75",[Hoppenstein]![Renewal]*0.01,[Hoppenstein]![Renewal]*0.02)



Try something more like:

Renewal: [Hoppenstein]![Renewal] *
IIf([Hoppenstein]![ProductID]="64" Or
[Hoppenstein]![ProductID]="128" Or
[Hoppenstein]![ProductID]="75",0.01,0.02)

Or, more concisely:

Renewal: Hoppenstein!Renewal * IIf(Hoppenstein!ProductID
IN("64","128"."75"), 0.01, 0.02)

That presumes that ProductID is a Text field. If it is a
numeric type field, then lose the quotes.

--
Marsh
MVP [MS Access]
  #4  
Old June 27th, 2008, 04:09 PM posted to microsoft.public.access.queries
Duane Hookom
external usenet poster
 
Posts: 7,177
Default Syntax for If then Conditional Statement

I would probably manage this data rather hard-coded values in expressions in
queries. What happens when you want to add ProductID 96 or remove 75? Do you
want to find and maintain expressions burried in queries?
http://weblogs.sqlteam.com/jeffs/arc...2/10/9002.aspx

If you don't want to store the 1% and 2% in tables, a compromise would be to
create a very simple user defined function that accepts the ProductID and
returns the percent. Save this function in a module with a name like
"modBusinessCalcs".

--
Duane Hookom
Microsoft Access MVP


"Melissa" wrote:

I'm trying to write a conditional statement in a query that gives me the
following:
If product ID = 64, 128, or 75, then the renewal rate is 1%. All other
product ID's get a renewal rate of 2%. My statement below gives me 1% for all
products, and I can't get the syntax right to give me the 2% value for all
other products. Anyone have any suggestions?

Renewal: IIf([Hoppenstein]![ProductID]="64" Or "128" Or
"75",[Hoppenstein]![Renewal]*0.01,[Hoppenstein]![Renewal]*0.02)
--
Thanks,
Melissa

  #5  
Old June 27th, 2008, 08:22 PM posted to microsoft.public.access.queries
Melissa
external usenet poster
 
Posts: 409
Default Syntax for If then Conditional Statement

Worked like a charm!
--
Thanks,
Melissa


"Marshall Barton" wrote:

Melissa wrote:

I'm trying to write a conditional statement in a query that gives me the
following:
If product ID = 64, 128, or 75, then the renewal rate is 1%. All other
product ID's get a renewal rate of 2%. My statement below gives me 1% for all
products, and I can't get the syntax right to give me the 2% value for all
other products. Anyone have any suggestions?

Renewal: IIf([Hoppenstein]![ProductID]="64" Or "128" Or
"75",[Hoppenstein]![Renewal]*0.01,[Hoppenstein]![Renewal]*0.02)



Try something more like:

Renewal: [Hoppenstein]![Renewal] *
IIf([Hoppenstein]![ProductID]="64" Or
[Hoppenstein]![ProductID]="128" Or
[Hoppenstein]![ProductID]="75",0.01,0.02)

Or, more concisely:

Renewal: Hoppenstein!Renewal * IIf(Hoppenstein!ProductID
IN("64","128"."75"), 0.01, 0.02)

That presumes that ProductID is a Text field. If it is a
numeric type field, then lose the quotes.

--
Marsh
MVP [MS Access]

  #6  
Old June 27th, 2008, 08:24 PM posted to microsoft.public.access.queries
Melissa
external usenet poster
 
Posts: 409
Default Syntax for If then Conditional Statement

I agree about finding expressions buried in queries. This might be a bit
beyond my talents, but I like a challenge, so I'll try it.
--
Thanks,
Melissa


"Duane Hookom" wrote:

I would probably manage this data rather hard-coded values in expressions in
queries. What happens when you want to add ProductID 96 or remove 75? Do you
want to find and maintain expressions burried in queries?
http://weblogs.sqlteam.com/jeffs/arc...2/10/9002.aspx

If you don't want to store the 1% and 2% in tables, a compromise would be to
create a very simple user defined function that accepts the ProductID and
returns the percent. Save this function in a module with a name like
"modBusinessCalcs".

--
Duane Hookom
Microsoft Access MVP


"Melissa" wrote:

I'm trying to write a conditional statement in a query that gives me the
following:
If product ID = 64, 128, or 75, then the renewal rate is 1%. All other
product ID's get a renewal rate of 2%. My statement below gives me 1% for all
products, and I can't get the syntax right to give me the 2% value for all
other products. Anyone have any suggestions?

Renewal: IIf([Hoppenstein]![ProductID]="64" Or "128" Or
"75",[Hoppenstein]![Renewal]*0.01,[Hoppenstein]![Renewal]*0.02)
--
Thanks,
Melissa

 




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:28 AM.


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