Results 1 to 9 of 9
  1. #1
    sheckay is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    May 2022
    Posts
    73

    Adding up entry selections from combo boxes on a form

    Hello. I have a form with a multiple combo boxes that have the same items to be selected. I'd like to know if there's a way to get a running total of the different selections? Say there's 10 combo boxes, and "bread", "milk", "butter", and sugar" are what can be chosen, combo box by combo box. I'd like to have 4 different totals boxes that carry a running total. "Bread Total", "Milk Total", "Butter Total", "Sugar Total". And the totals would be numeric of course. Can this be done?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    why are there so many combo boxes? Is it like:
    cboBread, with different types of bread
    and
    cboMilk, with different types of milk?

    if not, explain.
    If not, why not 1 list box with everything, and 1 filter combo box, to filter item types in the list
    combo values: Milk, breads, sugar,etc
    this prevents MORE combo boxes getting added for more food types.

    dbl-click the items in the listbox to add it to the cart. The cart form can subtotal by type.

  3. #3
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    It can certainly be done but it's definitely not typical. I'm trying to think of a way to do it that would be as dynamic/flexible, and maintainable as possible but it's tough not knowing much about your project. Maybe you could explain big picture what you're trying to do? Is this like a meal planner?

  4. #4
    sheckay is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    May 2022
    Posts
    73
    Thank you both. There are multiple boxes being shipped out per order. And they can and will vary from boxes to cartons to spools. And as they're entered/selected, I'd like a running total of what's been chosen.

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Perhaps you will get more specific help if you post a copy of the db
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    We need a LOT more information.
    For example, if you choose "Milk" from your "Milk" combo box, how do you know how many to total? What if Milk comes in different sizes - quarts, pints, gallons etc? How do you know what order is being fulfilled?

  7. #7
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    It's not exactly what OP asked for but it's the least code dependent option I could think of. The only code required will be to requery the totals.

    Click image for larger version. 

Name:	Untitled.jpg 
Views:	21 
Size:	106.4 KB 
ID:	48032

  8. #8
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Otherwise, another option that is more along the lines of what OP asked for, you can create a single generic function that you pass the value your trying to count and it will loop through a predefined list of comboboxs and count the matches. You can use this vba function in your text box control source. Something like.

    Code:
    Private Function ComboCount(match_value As String) As Long
    On Error GoTo ErrHandler
        Dim combo_names As String
        Dim combo_name As Variant
        Dim combo_arr() As String
        Dim running_sum As Long
        
        running_sum = 0
        
        '-----------------------------------------------------------------------
        '---------------------------- ENTER YOUR FORM'S COMBO BOX NAMES HERE !!!
        '-----------------------------------------------------------------------
        combo_names = "Combo0,Combo2,Combo4,Combo6,Combo8,Combo10,Combo12,Combo14,Combo16,Combo18"
        
        '-----------------------------------------------------------------------
        
        
        combo_arr = Split(combo_names, ",")
    
        For Each combo_name In combo_arr
            If Me.Controls(combo_name) = match_value Then
                running_sum = running_sum + 1
            End If
        Next combo_name
        
    ExitHandler:
        ComboSum = running_sum
        Exit Function
        
    ErrHandler:
        MsgBox Err.Description, vbInformation, "Error #" & Err.Number
        Resume ExitHandler
        
    End Function
    Then in a summary text box you would set the control source to something like =ComboCount("bread"). This is a lot more error prone, more work, less manageable, less flexible than the I approach I previously posted.

  9. #9
    sheckay is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    May 2022
    Posts
    73
    Sorry I haven't had a chance to thank any of you. Had a long hard day. But I should get a chance to try these out tomorrow. I'll keep you posted. Thank you all.

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

Similar Threads

  1. Replies: 6
    Last Post: 07-28-2020, 09:31 PM
  2. Replies: 7
    Last Post: 07-08-2015, 09:54 AM
  3. Replies: 5
    Last Post: 04-15-2015, 12:50 PM
  4. Combo Boxes, Selections, frustrations
    By redbull in forum Programming
    Replies: 14
    Last Post: 10-23-2012, 11:41 AM
  5. Replies: 3
    Last Post: 05-25-2010, 02:16 PM

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