Results 1 to 7 of 7
  1. #1
    everterra is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2014
    Location
    Gaia, Portugal
    Posts
    14

    How to count and sum registries from a table and pass it to a control in a form?

    Hello.

    In Access 2013 I have a table to registry the presents in a condominium meeting.


    Table Name: tbEntities


    Fields:


    tbEntId...tbPresent (yes / no)..........tbVotes
    1.........yes...........................5


    2.........no.............................3
    3.........yes............................4
    4.........no.............................6


    I want to put in a form (like a navigation/menu form, with no souce data):

    1. a control that count how many are present (= yes)
    Ex: Appearances 2
    2. a control that sum the votes of those present
    Ex: 9 Votes

    Can somebody help with this? Thanks.
    Last edited by everterra; 01-12-2015 at 02:51 AM.

  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,770
    Is tbPresent a yes/no data type field?

    Expression in textbox ControlSource and textboxes in form footer section:

    =Count(IIf(tbPresent=True, 1))

    =Sum(IIf(tbPresent=True, tbVotes, 0))
    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
    everterra is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2014
    Location
    Gaia, Portugal
    Posts
    14
    Thanks for your reply.


    Yes, the field tbPresent is yes/no data type.


    But the form is like a navigation/menu form with other source data...
    After use your sugestion, gives me #Error.

    Click image for larger version. 

Name:	2015-01-12_09h07_42.png 
Views:	9 
Size:	32.9 KB 
ID:	19303

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What do you mean 'like a navigation/menu'? Is this a form/subform arrangement? What you show looks like Single View. tbPresent is in the subform? Put the calcs into the footer of the subform.
    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.

  5. #5
    everterra is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2014
    Location
    Gaia, Portugal
    Posts
    14
    Thanks again June7.


    And no.
    The form is based in the table tbAssembleias.
    The Count field must show the results of a query based in the another table - tnEntidades or count what fields have "yes".
    The Sum field must show the sum of the tbVotes field.


    I have already a query who counts the presents and in the SQL view stays like:


    SELECT Count(tbEntidades.tbAssPresente) AS ContaPresentes, tbEntidades.tbAssPresente
    FROM tbEntidades
    GROUP BY tbEntidades.tbAssPresente
    HAVING (((Count(tbEntidades.tbAssPresente))=True) AND ((tbEntidades.tbAssPresente)=True));


    But I can not figure how to put the result in the field Count.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    If the field is not included in the form RecordSource, then options:

    1. subform bound to the aggregate query

    2. listbox that uses the aggregate query as RowSource

    3. domain aggregate function (DCount, DSum, etc)
    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.

  7. #7
    everterra is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2014
    Location
    Gaia, Portugal
    Posts
    14
    Ok, because it seemed more apropriated I experimented with your option 2, and resulted.


    Using a listbox, >Properties >Source >Source line, and using there the Constructor, I mounted a query.


    For the fist list box to show the Count, the result was:


    SELECT Count(tbEntidades.tbAssPresente) AS ContaPresentes, tbEntidades.tbAssPresente
    FROM tbEntidades
    GROUP BY tbEntidades.tbAssPresente
    HAVING (((Count(tbEntidades.tbAssPresente))=True) AND ((tbEntidades.tbAssPresente)=True));


    For the second list box to show the Sum, the result was:


    SELECT Sum(tbFrações.tbFrPerc) AS SomaDetbFrPerc, tbEntidades.tbAssPresente
    FROM tbFrações
    INNER JOIN tbEntidades ON tbFrações.tbFrId = tbEntidades.tbFrações.Value
    GROUP BY tbEntidades.tbAssPresente
    HAVING (((tbEntidades.tbAssPresente)=True));


    Many thanks for your help June7

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

Similar Threads

  1. Replies: 11
    Last Post: 11-13-2014, 08:52 PM
  2. Replies: 9
    Last Post: 03-18-2014, 07:02 PM
  3. Replies: 1
    Last Post: 03-15-2013, 12:03 PM
  4. Record Count based on Form control value
    By Monterey_Manzer in forum Forms
    Replies: 7
    Last Post: 11-29-2012, 10:47 AM
  5. Mathemathical calculations in registries
    By Cholomanchuten in forum Access
    Replies: 2
    Last Post: 08-15-2011, 12:12 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