Results 1 to 5 of 5
  1. #1
    carissa7 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2018
    Posts
    10

    Toggle form, manipulate toggle buttons upon clicking to calculate sum 

    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.

    Any help or ideas is appreciated. thanks!!

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    The form is connected to the query,with 2 extra fields ,each for each toggle.
    an extra unbound field for total:
    amt of qry+ amt toggle1 + amt toggle2

    Both toggles get a routine AddTogVals, to run if both are true,

    Code:
    sub toggle1_afterupdate()
    AddTogVals
    end sub
    
    sub toggle2_afterupdate()
    AddTogVals
    end sub
    
    Sub AddTogVals()
    If toggle1.value and toggle2.value then
       Toggle1fld=2
       Toggle2fld=3
    end sub

  3. #3
    carissa7 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2018
    Posts
    10
    i'm not too experienced with vba, 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.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Sum() is an aggregate function - it sums records, not values of same record.

    Maybe:

    =IIf(toggle1, AmountA, 0) + IIf(toggle2, AmountB, 0) + IIf(toggle3, AmountC, 0)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    What if you end up with a 4th, or 5th? Maybe use a Select Case block. To help with that, would probably need a db copy with at least the form and supporting table and/or query for this.
    But are we really talking toggle buttons, or are they option buttons? Not sure if that matters.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Toggle Buttons Programming
    By Kiwidude23 in forum Access
    Replies: 1
    Last Post: 10-25-2016, 05:23 AM
  2. Replies: 21
    Last Post: 06-03-2015, 07:14 PM
  3. Filtering Subform with Toggle Buttons
    By doubleohkevin in forum Forms
    Replies: 3
    Last Post: 09-30-2014, 02:13 PM
  4. Shape Effect on Toggle Buttons
    By dimoc in forum Access
    Replies: 5
    Last Post: 04-10-2014, 09:28 AM
  5. Replies: 1
    Last Post: 06-16-2012, 02:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums