How do I make part of my form dependent on a check box?

G

Guest

I'm using access 2003. I am trying to make my form calculate sales tax if my
box is checked.
 
J

John Vinson

I'm using access 2003. I am trying to make my form calculate sales tax if my
box is checked.

Since I can't see your table or form structure I'm groping in the dark
a bit, but try setting the Control Source of a textbox to

=[Price] * (1 + IIf([Taxable], [TaxRate], 0))

John W. Vinson[MVP]
 
G

Guest

What does all that mean? Is if represensented by a symbol.

John Vinson said:
I'm using access 2003. I am trying to make my form calculate sales tax if my
box is checked.

Since I can't see your table or form structure I'm groping in the dark
a bit, but try setting the Control Source of a textbox to

=[Price] * (1 + IIf([Taxable], [TaxRate], 0))

John W. Vinson[MVP]
 
J

John Vinson

What does all that mean? Is if represensented by a symbol.

Iif() - Immediate If - is the name of a builtin Access function. To
break this down into logical bits:

=[Price] * (1 + IIf([Taxable], [TaxRate], 0))

= means "An expression follows, set this textbox to display the result
of the expression"

[Price] should be replaced by the name of the field in your table
which contains the price

That price will by multiplied (* is the multiplication operator) by
the expression in parentheses

If the item is not taxable, you want to multiply by 1 (that is, just
have the expression return the untaxed price); if it is taxable, you
want to multiply by 1.065 if the tax rate is 6.5%, or 1 plus whatever
the taxrate is. I assumed that you have a yes/no field named [Taxable]
which is TRUE if the item is taxable, and another field [TaxRate]
containing the percentage tax rate.

The IIF function takes three arguments: it evaluates the first one as
being either TRUE or FALSE. If it is TRUE, it returns the second
argument; if FALSE, it returns the third. So the IIF function will
return 0.065 if [Taxable] is True and [TaxRate] is 0.065 (=6.5%); if
[Taxable] is False, then it doesn't matter what the taxrate is, the
IIF function will return 0, the third argument.

You would change the fieldnames to match those in your table (which of
course I cannot see) and put the entire expression into the Control
Source property of a textbox on the form to calculate and display the
price including the sales tax. Rounding to even cents is probably a
good idea too: so you would use instead

=Round([Price] * (1 + IIf([Taxable], [TaxRate], 0)), 2)


John W. Vinson[MVP]
 
G

Guest

John
Your great! Thanks for the help. Is there a place to learn the expressions.
I'm new to access. Is th IIf in the expressiobn builder?

John Vinson said:
What does all that mean? Is if represensented by a symbol.

Iif() - Immediate If - is the name of a builtin Access function. To
break this down into logical bits:

=[Price] * (1 + IIf([Taxable], [TaxRate], 0))

= means "An expression follows, set this textbox to display the result
of the expression"

[Price] should be replaced by the name of the field in your table
which contains the price

That price will by multiplied (* is the multiplication operator) by
the expression in parentheses

If the item is not taxable, you want to multiply by 1 (that is, just
have the expression return the untaxed price); if it is taxable, you
want to multiply by 1.065 if the tax rate is 6.5%, or 1 plus whatever
the taxrate is. I assumed that you have a yes/no field named [Taxable]
which is TRUE if the item is taxable, and another field [TaxRate]
containing the percentage tax rate.

The IIF function takes three arguments: it evaluates the first one as
being either TRUE or FALSE. If it is TRUE, it returns the second
argument; if FALSE, it returns the third. So the IIF function will
return 0.065 if [Taxable] is True and [TaxRate] is 0.065 (=6.5%); if
[Taxable] is False, then it doesn't matter what the taxrate is, the
IIF function will return 0, the third argument.

You would change the fieldnames to match those in your table (which of
course I cannot see) and put the entire expression into the Control
Source property of a textbox on the form to calculate and display the
price including the sales tax. Rounding to even cents is probably a
good idea too: so you would use instead

=Round([Price] * (1 + IIf([Taxable], [TaxRate], 0)), 2)


John W. Vinson[MVP]
 

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