Results 1 to 8 of 8
  1. #1
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727

    Summing up text boxes

    I have this in the Lost Focus event:



    Private Sub txtSumAmtsDue1_LostFocus()

    Me.txtAmtDue = [txtSumAmtsDue1] + [txtSumAmtsDue2] + [txtSumAmtsDue3] + [txtSumAmtsDue4] _
    + [txtSumAmtsDue5] + [txtSumAmtsDue6] + [txtSumAmtsDue7]

    End Sub

    When I test it out it, the text box txtAmtsDue just goes blank. I also tried using the code above with me.txtSumAmtsDue1 + me.txtSumAmtsDue2 + etc....

    with the same results. What am I doing wrong?

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    It's probably because when [txtSumAmtsDue1] loses the focus, the others are still Null, so the sum is Null.

    Try using nz([txtSumAmtsDue1],0) + nz([txtSumAmtsDue2],0) + ... to change any Nulls to 0.

    Don't forget to include that sum in the LostFocus event of all 7 textboxes.

    John

  3. #3
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    You were right! Now I got it to work however, I am now having a problem. Because these text boxes are unbound, they are not tied to any record in particular. So when go to another record, these unbound text boxes stay the same and will confuse the user because the data is static. How can I make it follow a record without having to save it to a table?

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Do you mean retain the Old Values? If so, then;
    Me.ControlName = Me.ControlName.OldValue

  5. #5
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Thanks. What event would that go under? Of would it just go under the current event for the form itself?

  6. #6
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    I just tested it in the form's current event and it does not keep the old value. Example, if I enter $35 in the text box, this data will show for every single record that I navigate to. I'm thinking there is no way to assign this unbound data to the record because it is not being saved into the table. I may just have to create these fields in the table then set the source of these text boxes to that just so it can follow the specific record.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,642
    That is true, unbound controls will show the same value for every record unless the ControlSource is an expression calculating with values of bound controls. How else could an unbound control behave?
    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.

  8. #8
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    If I understand you correctly, you do not want to keep those fields' data when moving from one record to another.

    All you need to do is set them to 0 in the form's On Current Event:

    [txtSumAmtsDue1] = 0
    [txtSumAmtsDue2] = 0
    ...

    The On current event will fire every time you move from one record to another, including a new one.

    John

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. Summing a bunch of text boxes
    By athyeh in forum Programming
    Replies: 7
    Last Post: 09-03-2013, 04:59 PM
  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