Share via

Access DB toggle form, manipulate toggle buttons upon clicking to calculate sum

Anonymous
2018-05-19T14:10:29+00:00

First off - I'm pretty new to access so any help is really appreciated.

I have a form in access database with toggle buttons next to amounts.

For example) Amount A =2; toggle button. Amount B = 3; toggle button. The form has a record source pointing to a query called "values" that calculates all the values.

I have a sum text box below the amounts,  the sum text box has a formula that says [amountA]+[amountB]. Instead of the formula how can I remove the formula and add functionality that says =IF[amount A] toggle button = pressed on and if amount b toggle button = pressed on then sum the two amounts in the text box sum. if its pressed off do not include the amounts in the total.

Can I just write a formula in the sum text box =sum([AmountA] and [Amount B]),IIF(toggle1 = "True" and toggle 2="true"),1,0))??? But then how do I add logic for multiple scenarios. Where toggle 1 is clicked and then lets say I had a 3rd amount [amount C] toggle 3 is clicked. Basically only if toggle is clicked e.g. "true" does it get added.    

Any help or ideas is appreciated. thanks!!

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2018-05-19T15:38:27+00:00

The expression for the control's ControlSource property would be along these lines:

    =[AmountA]*IIf([tglA],1,0)+[AmountB]*IIf([tglB],1,0)+[AmountC]*IIf([tglC],1,0)

A toggle button has values of a Boolean TRUE if pressed or FALSE if not pressed (implemented in Access as -1 and 0 respectively), so the IIf function will return a value of 0 or 1 depending on the state of the toggle button.  Note that none of the amount controls can be Null, so be sure that the query returns a zero rather than a Null for each if necessary.  Otherwise a Null would propagate in the arithmetical addition operations, and the expression as a whole would evaluate to Null.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2018-05-19T16:08:24+00:00

    Amazing!! works perfectly, thank you so much and thanks for always responding!!

    Was this answer helpful?

    0 comments No comments