How do I create subtotals on a form that relate to values selected on a list?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MidgeY2K
    New Member
    • Jan 2010
    • 2

    How do I create subtotals on a form that relate to values selected on a list?

    I have an unbound listbox (list1) on my form.
    Another unbound listbox (list2) that shows the totals of the values in the months in (list1)
    I am trying to add a third listbox (list3) that subtotals the selected items in (list1)

    I have multi-select set to extended to allow the multiselection.

    I suspect I need to code something with the listindex and itemsselected?

    Was hoping to copy (list2) query and add a filter using listindex, but can't get my head around that.

    Would put my code on here, but there is an awful lot more going on in this form, and it would probably complicate things...and my coding is untidy !!! lol
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    I would simplify things by adding a YesNo field to the table. This enables the user to select rows without the CTRL pressed and thus "more stable" (a simple click can undo such a multiselect :-( ).

    Having the YesNo field will easily allow you to total the rows by adding the YesNo field to be True.

    You could even add a (de-)select all button that performs an UPDATE of the YesNo field for all rows in the table.

    When you check my Left/Right listbox sample (http://bytes.com/attachments/attachm...tright2000.zip) you can see how I use such a field to determine in what listbox a row has to appear and by the > and >> buttons how the UPDATE is handled.

    Getting the idea ?

    Nic;o)

    Comment

    • MidgeY2K
      New Member
      • Jan 2010
      • 2

      #3
      Hi Nico,
      Thanks for the response. I get the idea, and have downloaded and looked at your code (which I may use elsewhere!) but I'm not sure as I can get this to practically work for my requirements. What I am after is similar to Excel where you have the "quick sum" ability in the bottom right hand corner in the status bar. You can easily and quickly hold down control/Shift and select multiple non-adjacent cells and see the sum instantly, but affect nothing structurally. (Stability is not an issue, as it is only meant to be a quick and dirty calc. to save time.) This access application I am building will be used in an active meeting, and will be fast paced, so speed is required even if I have to work on some more complicated code. Any other angle or a way you can think of?

      Thanks for your thoughts so far.
      MidgeY2K

      Comment

      • nico5038
        Recognized Expert Specialist
        • Nov 2006
        • 3080

        #4
        The YesNo field approach can be used for a quick sum by using an unbound field with a DSUM like:
        Code:
        =DSUM("MyNumericValue","MyTable","YesNo=True")
        The other solution would be to loop in code through the SelectedItems of the listbox and sum them in code.

        Nic;o)

        Comment

        Working...