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  

Coditional IIf with an AND/OR statement



 
 
Thread Tools Display Modes
  #1  
Old May 22nd, 2010, 05:55 PM posted to microsoft.public.access.queries
theref147
external usenet poster
 
Posts: 3
Default Coditional IIf with an AND/OR statement

Trying to get a query to determine a tax rate based on the province on a
record.
It should look at the [Prov] field and based on what is in that field come
up with the corresponding tax rate. eg IIf ([Prov]= "ON" and [Date of
Service]2010/06/30,.13,.05, OR IIf ([Prov]="BC" and [Date of
Service]2010/06/30,.12,.05) or something of this nature. I am not sure how
to write the formula could someone help.
  #2  
Old May 22nd, 2010, 07:11 PM posted to microsoft.public.access.queries
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Coditional IIf with an AND/OR statement

You may find it easier to write a function and pass the Province and Date as
parameters to the function...

Reading between the lines, try something like:

Switch([Prov] = 'BC', IIf([Date of Service] #2010-06-30#, .12, .05),
[Prov] = 'ON', IIf([Date of Service] #2010-06-30#, .13, .05),

....
)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"theref147" wrote in message
...
Trying to get a query to determine a tax rate based on the province on a
record.
It should look at the [Prov] field and based on what is in that field come
up with the corresponding tax rate. eg IIf ([Prov]= "ON" and [Date of
Service]2010/06/30,.13,.05, OR IIf ([Prov]="BC" and [Date of
Service]2010/06/30,.12,.05) or something of this nature. I am not sure
how
to write the formula could someone help.



  #3  
Old May 22nd, 2010, 07:33 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Coditional IIf with an AND/OR statement

I think your best and easiest method is to create a RateTable of criteria and
tax rate like this --
Prov RateStart RateEnd Rate
ON 6/30/2010 0.0415
BC 6/30/2010 0.049
ON 5/10/2010 6/30/2010 0.0415
BC 4/23/2010 6/30/2010 0.049

And then this IIF statement ---
IIF([YourTable].[Prov] = [RateTable].[Prov] AND [YourTable].[Date of
Service] Between [RateTable].[RateStart] AND Nz([RateTable].[RateEnd],
#12/31/9999#)


--
Build a little, test a little.


"theref147" wrote:

Trying to get a query to determine a tax rate based on the province on a
record.
It should look at the [Prov] field and based on what is in that field come
up with the corresponding tax rate. eg IIf ([Prov]= "ON" and [Date of
Service]2010/06/30,.13,.05, OR IIf ([Prov]="BC" and [Date of
Service]2010/06/30,.12,.05) or something of this nature. I am not sure how
to write the formula could someone help.

  #4  
Old May 23rd, 2010, 01:40 AM posted to microsoft.public.access.queries
theref147
external usenet poster
 
Posts: 3
Default Coditional IIf with an AND/OR statement

I tried to copy this into the query but kept comming up with invalide use of
] or !. Can this also do the other provinces within the same field? This
field name is TaxRate.

"Douglas J. Steele" wrote:

You may find it easier to write a function and pass the Province and Date as
parameters to the function...

Reading between the lines, try something like:

Switch([Prov] = 'BC', IIf([Date of Service] #2010-06-30#, .12, .05),
[Prov] = 'ON', IIf([Date of Service] #2010-06-30#, .13, .05),

....
)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"theref147" wrote in message
...
Trying to get a query to determine a tax rate based on the province on a
record.
It should look at the [Prov] field and based on what is in that field come
up with the corresponding tax rate. eg IIf ([Prov]= "ON" and [Date of
Service]2010/06/30,.13,.05, OR IIf ([Prov]="BC" and [Date of
Service]2010/06/30,.12,.05) or something of this nature. I am not sure
how
to write the formula could someone help.



.

  #5  
Old May 23rd, 2010, 01:44 PM posted to microsoft.public.access.queries
theref147
external usenet poster
 
Posts: 3
Default Coditional IIf with an AND/OR statement

Thank you. But I need this in a query with 7 Provinces and each changeing
rates as of 2010/06/30. NO luck with trying to copy and paste the function
into the equation builder - I am a rookie at this so I need more help if
possible.

"Douglas J. Steele" wrote:

You may find it easier to write a function and pass the Province and Date as
parameters to the function...

Reading between the lines, try something like:

Switch([Prov] = 'BC', IIf([Date of Service] #2010-06-30#, .12, .05),
[Prov] = 'ON', IIf([Date of Service] #2010-06-30#, .13, .05),

....
)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"theref147" wrote in message
...
Trying to get a query to determine a tax rate based on the province on a
record.
It should look at the [Prov] field and based on what is in that field come
up with the corresponding tax rate. eg IIf ([Prov]= "ON" and [Date of
Service]2010/06/30,.13,.05, OR IIf ([Prov]="BC" and [Date of
Service]2010/06/30,.12,.05) or something of this nature. I am not sure
how
to write the formula could someone help.



.

  #6  
Old May 23rd, 2010, 03:22 PM posted to microsoft.public.access.queries
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Coditional IIf with an AND/OR statement

Hopefully you realize that the ... in there was to indicate it wasn't
complete.

Your Switch statement can be expanded for as many provinces as you like:

Switch([Prov] = 'BC', aaaa, [Prov] = 'AB', bbbb, [Prov] = 'SK', cccc, [Prov]
= 'MB', dddd, [Prov] = 'ON', eeee, [Prov] = 'QC', ffff, [Prov] = 'NB', gggg,
[Prov] = 'NS', hhhh, [Prov] = 'PE', iiii, [Prov] = 'NL', jjjj)

For those provinces that aren't getting HST, bbbb, cccc, etc can simply be
the PST rate. For those provinces that are getting HST, aaaa, eeee, etc will
be an IIf statement that decides whether to use the old PST rate or the new
HST rate.

On the other hand, having the data in a table (as Karl suggested) or calling
a function (as I originally suggested) is a far better approach.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"theref147" wrote in message
...
Thank you. But I need this in a query with 7 Provinces and each changeing
rates as of 2010/06/30. NO luck with trying to copy and paste the
function
into the equation builder - I am a rookie at this so I need more help if
possible.

"Douglas J. Steele" wrote:

You may find it easier to write a function and pass the Province and Date
as
parameters to the function...

Reading between the lines, try something like:

Switch([Prov] = 'BC', IIf([Date of Service] #2010-06-30#, .12, .05),
[Prov] = 'ON', IIf([Date of Service] #2010-06-30#, .13, .05),

....
)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"theref147" wrote in message
...
Trying to get a query to determine a tax rate based on the province on
a
record.
It should look at the [Prov] field and based on what is in that field
come
up with the corresponding tax rate. eg IIf ([Prov]= "ON" and [Date of
Service]2010/06/30,.13,.05, OR IIf ([Prov]="BC" and [Date of
Service]2010/06/30,.12,.05) or something of this nature. I am not
sure
how
to write the formula could someone help.



.



 




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 09:13 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.