check box

B

binny

how do I enter a value into field using a check box
if the insurance check box is checked I want to enter $7.50 into the
insurance field
if the box is not checked I want the field to have the default value of 0
 
C

CJ

Hi Binny:

You need to use an IIF function in a query.
Let's say your check box is named Insurance. You would create a calculated
field whose formula might look like this:

InsuranceRate: IIf([Insurance]=True,7.50,0))
 
B

binny

Hi CJ
this might sound silly how do you make a calulated field in a table
the only reference I can find is in a query
--
binny


CJ said:
Hi Binny:

You need to use an IIF function in a query.
Let's say your check box is named Insurance. You would create a calculated
field whose formula might look like this:

InsuranceRate: IIf([Insurance]=True,7.50,0))

--
HTH

CJ
---------------------------------------------------------
Know thyself, know thy limits....know thy newsgroups!

binny said:
how do I enter a value into field using a check box
if the insurance check box is checked I want to enter $7.50 into the
insurance field
if the box is not checked I want the field to have the default value of 0
 
E

Evi

I see what you mean, Binny, you need to store this value in your table
because if the Insurance rate changes then the calculation would change for
past records as well as future ones.
You are being Good and using a form to enter your data, aren't you Binny?

If you are, then, use the After Update Event of your checkbox ie
In the Form's Design View, Click on Properties, Click on your checkbox,
click on the Events tab of Properties.
Click next to After Update.

Choose Event Procedure, click just right of that to open a Code page.

Above the words End Sub, type in

If Me.[Insurance] = True Then
Me.[MyRateField] = 7.5
End if


Because it is in the AfterUpdate Event of the Checkbox, it occurs whenever
the checkbox is updated with a tick.

Change the names, Insurance and MyRateField to the real name of your
controls.

There are a number of refinements you may want to consider.
Do you want this 7.5 to be entered only if you are entering a new record?
Do you want the 7.5 to be removed if you untick the checkbox.

Most importantly, it isn't usually a good idea to enter data (7.5) in code.
You may want to consider creating a table (TblInsuranceRate) which contains
only the current rate and then have the code say

If Me.[Insurance] = True Then
Me.[MyRateField] = DLookup("[InsuranceRate]","TblInsuranceRate")
End if

This makes it easier for you (or another user) to change that field.

Evi









binny said:
Hi CJ
this might sound silly how do you make a calulated field in a table
the only reference I can find is in a query
--
binny


CJ said:
Hi Binny:

You need to use an IIF function in a query.
Let's say your check box is named Insurance. You would create a calculated
field whose formula might look like this:

InsuranceRate: IIf([Insurance]=True,7.50,0))

--
HTH

CJ
---------------------------------------------------------
Know thyself, know thy limits....know thy newsgroups!

binny said:
how do I enter a value into field using a check box
if the insurance check box is checked I want to enter $7.50 into the
insurance field
if the box is not checked I want the field to have the default value of 0
 
B

binny

thanks I had a feeling VBA code would be involved Access certainly is limited
with out VBA
Putting the insurance rate in another table with an adjustment form is a
good idea,
your right it changes all the time.
--
binny


Evi said:
I see what you mean, Binny, you need to store this value in your table
because if the Insurance rate changes then the calculation would change for
past records as well as future ones.
You are being Good and using a form to enter your data, aren't you Binny?

If you are, then, use the After Update Event of your checkbox ie
In the Form's Design View, Click on Properties, Click on your checkbox,
click on the Events tab of Properties.
Click next to After Update.

Choose Event Procedure, click just right of that to open a Code page.

Above the words End Sub, type in

If Me.[Insurance] = True Then
Me.[MyRateField] = 7.5
End if


Because it is in the AfterUpdate Event of the Checkbox, it occurs whenever
the checkbox is updated with a tick.

Change the names, Insurance and MyRateField to the real name of your
controls.

There are a number of refinements you may want to consider.
Do you want this 7.5 to be entered only if you are entering a new record?
Do you want the 7.5 to be removed if you untick the checkbox.

Most importantly, it isn't usually a good idea to enter data (7.5) in code.
You may want to consider creating a table (TblInsuranceRate) which contains
only the current rate and then have the code say

If Me.[Insurance] = True Then
Me.[MyRateField] = DLookup("[InsuranceRate]","TblInsuranceRate")
End if

This makes it easier for you (or another user) to change that field.

Evi









binny said:
Hi CJ
this might sound silly how do you make a calulated field in a table
the only reference I can find is in a query
--
binny


CJ said:
Hi Binny:

You need to use an IIF function in a query.
Let's say your check box is named Insurance. You would create a calculated
field whose formula might look like this:

InsuranceRate: IIf([Insurance]=True,7.50,0))

--
HTH

CJ
---------------------------------------------------------
Know thyself, know thy limits....know thy newsgroups!

how do I enter a value into field using a check box
if the insurance check box is checked I want to enter $7.50 into the
insurance field
if the box is not checked I want the field to have the default value of 0
 
E

Evi

Don't feel uneasy about using VBA, Binny. It actually makes more sense than
you would think In fact, you will eventually get to the stage where you
find Excel annoying because its VBA is so limited.

If you are unsure about any of the stages of using it, please say so and we
can step you through it. Supply your exact InsuranceRate Table name (if you
decide to use one) and field names if you are still unsure about how to edit
the code I wrote below and I will put them into the code so that you can see
them in situe

Evi

binny said:
thanks I had a feeling VBA code would be involved Access certainly is limited
with out VBA
Putting the insurance rate in another table with an adjustment form is a
good idea,
your right it changes all the time.
--
binny


Evi said:
I see what you mean, Binny, you need to store this value in your table
because if the Insurance rate changes then the calculation would change for
past records as well as future ones.
You are being Good and using a form to enter your data, aren't you Binny?

If you are, then, use the After Update Event of your checkbox ie
In the Form's Design View, Click on Properties, Click on your checkbox,
click on the Events tab of Properties.
Click next to After Update.

Choose Event Procedure, click just right of that to open a Code page.

Above the words End Sub, type in

If Me.[Insurance] = True Then
Me.[MyRateField] = 7.5
End if


Because it is in the AfterUpdate Event of the Checkbox, it occurs whenever
the checkbox is updated with a tick.

Change the names, Insurance and MyRateField to the real name of your
controls.

There are a number of refinements you may want to consider.
Do you want this 7.5 to be entered only if you are entering a new record?
Do you want the 7.5 to be removed if you untick the checkbox.

Most importantly, it isn't usually a good idea to enter data (7.5) in code.
You may want to consider creating a table (TblInsuranceRate) which contains
only the current rate and then have the code say

If Me.[Insurance] = True Then
Me.[MyRateField] = DLookup("[InsuranceRate]","TblInsuranceRate")
End if

This makes it easier for you (or another user) to change that field.

Evi









binny said:
Hi CJ
this might sound silly how do you make a calulated field in a table
the only reference I can find is in a query
--
binny


:

Hi Binny:

You need to use an IIF function in a query.
Let's say your check box is named Insurance. You would create a calculated
field whose formula might look like this:

InsuranceRate: IIf([Insurance]=True,7.50,0))

--
HTH

CJ
---------------------------------------------------------
Know thyself, know thy limits....know thy newsgroups!

how do I enter a value into field using a check box
if the insurance check box is checked I want to enter $7.50 into the
insurance field
if the box is not checked I want the field to have the default
value
of 0
 

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