Full Version: How To..."When a Checkbox Is Checked Do Calculations"
UtterAccess Forums > Microsoft® Access > Access Forms
Hello !
I have a form that has 2 checkboxes "State" and "Federal" taxes. I would like to perform calculations when either or both of those checkboxes are checked. Then put the results of that calculation in separate fields in that same form. As well, if any of those checkboxes are NOT checked, leave those same results fields blank in that same form. How do I do this ?
Example...If an item is taxable for either Federal and/or State taxes the user will check the appropriate checkboxes. If either or both of those checkboxes are checked, I would like Access to perform the tax rate calculation and put the results in a separate field for each checkbox that is checked. If any of the 2 checkboxes are NOT checked, I would like access to not calculate anything and leave the respective fields blank.
Thanking you in advance for any help you can provide me with !
Hi Paul,
Welcome to Utter Access!
I hope you are only doing this for display purposes because it is not recommended to store calculated values.
In the AfterUpdate event of the checkboxes, you can do something like:
If Me.NameOfCheckbox Then
End If
Hope that helps...
Actually, this is one of the situations when a lot of developers do elect to store calculated values.
For instance, if you're calculating the area of a room, the formula would be
Area = Length * Width
There is no reason to store Area, because, because the Length and Width is stored and the formula will never change.
But if you're calculating, say, sales tax (VAT to our brethren across The Pond) then
SalesTax = ItemCost * TaxRate
Because sales taxes frequently change over time, you're faced with how to ensure that whenever the calculation is run, it will be run with the tax rate that was current at the time of the purchase!
You can
1) Store the tax rate in the record
2) Store the calculated sales tax
3) Have a separate tax rate table with fields for the tax rate as well as the start and ending dates those rates were in effect

Method 1 & 2 involve storing a value, and as a rule, in this case I'd store the rate. But if these taxes you're speaking of involve factors other than a simple rate, it might be better to store the result than to store multiple values needed to make the calculations.
Method 3 is the most complicated, because each time you go to do the re-calculation you have to go to the rates table and check the date on your record with the dates in the table then pull the appropriate rate.
Hi Again and thanks for your response !
irst let me say i am quite new to programming in MS Access as well as VBA, so please be gentle with me hahahahahah !
In your response here, you use the term "Me.????" I understand everything that follows that term. What exactly does the "Me." term mean ? Is it a VBA term that has to be in the code, or does the "Me." term have to be edited to my specific string of text ?
Thanks Again !
This is a programming shortcut which lets the programmer refer to the current CLASS object. Most of the time, in Access, you would be referring to a form or report using this. It can also apply to custom classes as well, but is less prevalent unless custom classes are being used.
Let's say you have a form named "frmMain" and you have a text box there called "txtEntry" and you wanted to refer to that text box in code. A fully-qualified reference would be Forms!frmMain.txtEntry but you could also refer to it using the shortcut (as long as the code is ON frmMain): Me.txtEntry
Hi Again,
irst let me tell you i am very new to MS Access and VBA, so please be gentle with me hahahahaha !
Thank you for your response and help, I really appreciate it !
I will digest what u responded with and apply it to my form. If i need any more help, I will contact you again !
Thanks Again !
P.S. Perhaps you can take a look at my other post titled "Not In List Value To A Combo Box" Problem i am having ?
Hi Bob,
Thanks for your response !
Ok I got it now !
Again a sincere thanks !
Actually, with missinglinq's method 3, you would only need a start date for each tax rate change (an ending date would be the same as the start date of the next tax rate).
When it's just a matter of finding the tax rate with the most recent start date that occurs before the date of the sale.
For instance, in a query of bills, you could use this formula to get the tax rate for the bill:
ThisTaxRate: DLookUp("[sngTaxRate]","tblTaxRates","[TaxRateStartDate] = #" & DMax("[TaxRateStartDate]","tblTaxRates","[TaxRateStartDate] < #" & [DateBilled] & "#") & "#")
Hope this helps,
Actually, I have a sample that is just like this basically. See here (if anyone is interested)
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.