Results 1 to 8 of 8
  1. #1
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170

    Summing a bunch of text boxes

    Hello All,

    I have developed a form that I have users inputting production numbers.

    Txtbox 1
    Txtbox 2
    Txtbox 3


    .
    .
    .
    Txtbox15

    As this person inputs into the form, I have a Txtbox TotalProd that I would like to sum up all the numbers that I have entered into each Txtbox1-15

    The only way that I can think to do this is to add in an after_update event into each Txtbox1-15 that goes something like:

    Code:
    Private Sub Txtbox1_AfterUpdate 
    
    Me.TotalProd = Txtbox1
    
    End Sub
    
    Private Sub Txtbox2_AfterUpdate
    
    Me.TotalProd = Txtbox1 + Txtbox 2
    
    End Sub
    And so on and so forth.. Is there a more efficient way to accomplish my goal?

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    In the TotalProd textbox, set it's control source to Nz([Txtbox1],0)+Nz[(Txtbox2],0)+ Nz([Txtbox3],0)+.... and so on.

  3. #3
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    That's the way to do it, because despite the logical way of entering this data, i.e. Txtbox1, Txtbox2,
    Txtbox3, etc., you really have no idea of what order the user will enter this data! If your Form were based on a Query you could do a Calculated Field, there, but the expression would be the basically same.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    Exactly. I do have a question though, why were you so adamant about the total fields not needing to be recorded? How does it hurt?

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    1. Re-running the Calculations is almost always going to be faster than retrieving the data.
    2. You're wasting space storing easily reproducible data.
    3. If one or more components of the Calculation should change, especially thru some action other than thru the original Form, at a date after the original data input, you run the chance that the stored Calculation Value will remain the same, which will then be incorrect.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    Quote Originally Posted by Missinglinq View Post
    1. Re-running the Calculations is almost always going to be faster than retrieving the data.
    2. You're wasting space storing easily reproducible data.
    3. If one or more components of the Calculation should change, especially thru some action other than thru the original Form, at a date after the original data input, you run the chance that the stored Calculation Value will remain the same, which will then be incorrect.

    Linq ;0)>
    All excellent points. Thank you.

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Just to be clear, like most 'rules' there are exceptions. When dealing with Sales Tax/VAT, which can change, over time, you have the choice of storing the tax rate for each transaction, using the current tax rate, or with storing the calculated 'price + tax'. Every developer has his preference. One way you're storing a calculated value, the other way you're storing redundant data. I had an app where the NextVisitDate was the LastVisitDate + VisitFrequency, where I really had to store the calculated NextVisitDate. But for the vast majority of situations, the rule is still 'do not store calculated values!'

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 9
    Last Post: 06-04-2014, 10:45 AM
  2. Replies: 9
    Last Post: 03-22-2013, 06:37 AM
  3. Replies: 4
    Last Post: 03-01-2013, 11:49 AM
  4. Replies: 3
    Last Post: 02-07-2013, 09:53 PM
  5. Summing two list boxes on a form
    By TinaCa in forum Forms
    Replies: 1
    Last Post: 06-09-2012, 01:28 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