Results 1 to 10 of 10
  1. #1
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43

    Thumbs up <Solved>Count how many records display 0

    Hello everyone,



    First off thank you for your time/help.

    I am trying to count the records in Total Column that display 0 from a Sub Form into my Main Form into an unbound box.
    Currently I have

    Main Form

    unbound box - (code to pull count of 0's) which in this case should display 2 since there is total of 2 employees with 0 across in the Total Column


    Sub Form - which data displays just as you see below
    In my Sub Form the Name, Test 1, Test 2 are fields from a table.
    Total is an unbound field that is =[Test 1] + [Test 2]
    Name Test 1 Test 2 Total
    Tom 1 0 1
    Betty 1 1 2
    Kim 0 0 0
    Hank 2 1 3
    Tim 0 0 0
    Last edited by tareyj8569; 08-03-2015 at 07:29 PM. Reason: Solved

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Textbox in subform footer:

    =Sum(IIf([Test 1] + [Test 2] = 0, 1, 0))

    If subform is in datasheet, a textbox on main form can reference the subform textbox.

    =[subform container name].Form.textboxname
    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.

  3. #3
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43
    very nice, are you allowed to do more than one =SUM like that or just one per subform? a sum for the tests and if i wanted to do a sum on the names could that be done or no?

  4. #4
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43
    This worked perfectly btw, was just curious about below.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Do as many as you want. Just means more textboxes.

    Curious about what below?
    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.

  6. #6
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43
    When i posted that second comment I should of said above not below=P... when i try to do more than one sumif i get errors throughout my main form, but if i do one sumif no issues, maybe i am trying to code it wrong now that i look at it.. how would i change it so it would count any of them that is greater than 0? =Sum(IIf([Test 1] + [Test 2] = >0, 1, 0)) is what i tried but did not seem to do it correct.. so from example above i want it to say 3 have numbers

  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,771
    Post the expressions you attempted. Aggregate functions (Sum, Count, Avg, etc) must refer to fields of form RecordSource not textboxes.
    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
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43
    Main Form
    (This is text 1)
    =[Subform].[Form]![text2]

    Subform
    (This is Text2) in the footer of subform
    =Sum(IIf([Test 1] + [Test 2] = 0, 1, 0))

    This works no problem

    Than if I try to duplicate the same thing
    (This is text 3)
    =[Subform].[Form]![text4]

    Subform
    (This is Text4)
    =Sum(IIf([Test 1] + [Test 2] = >0, 1, 0))

    I get an #errors on my countifs in the main form but my initial sum works fine.
    But if i only have one Sumif in the subfom everything is fine. (even if i just copy and paste the same working one twice it will freak out the main form)
    Hope i didnt make things to complicated

  9. #9
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43
    Oh, Jeeze disregard the #Errors, when i did a copy paste it pasted a textbox down in the footer of the form and was messing everything.
    So only issue now is to get it to count how many are greater than 0 instead of how many are 0 which is working. For some reason I cannot figure out how to just count how many = greater than 0. I keep getting a total of 6 instead of 3 as in count

  10. #10
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43
    wooo got it, =Sum(IIf([Test 1] + [Test 2] = >0, 1, 0)) had to get rid of the 2nd = so =Sum(IIf([Test 1] + [Test 2] >0, 1, 0))
    thanks for time and help

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

Similar Threads

  1. Replies: 2
    Last Post: 04-30-2013, 07:55 PM
  2. COUNT Group Count Records COUNT FUNCTION
    By PMCOFFEY in forum Access
    Replies: 9
    Last Post: 11-09-2012, 09:40 PM
  3. Display results with count of 0
    By jbickl in forum Reports
    Replies: 2
    Last Post: 02-06-2012, 07:07 AM
  4. Replies: 6
    Last Post: 07-25-2011, 01:54 PM
  5. Display record count
    By jgelpi16 in forum Reports
    Replies: 5
    Last Post: 11-30-2010, 09:02 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