Getting total counts of types in column, for example gender

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • artemetis
    New Member
    • Jul 2007
    • 76

    Getting total counts of types in column, for example gender

    I have a table (tblMain) with field Gender. I am trying to get a count in SQL of Female and Male personnel so I can update a form containing two fields "Male = and Female = ".

    The values stored in the tbl are "M and F".

    Thanks!
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    What have you tried so far?

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Use an aggregate query grouping by the gender. If you really need the results in two different columns, use a cross tab.

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        ahh, rabbit... I was going to suggest that... just wanted to see what they had tried so far :)

        (although I have a warm fuzzy that I was on the right track)

        :)

        -z

        Comment

        • artemetis
          New Member
          • Jul 2007
          • 76

          #5
          I have tried the aggregate query.

          This query gives me the correct counts, but not sure how to call the count number in the report field:

          Code:
          SELECT tblMain.Gender, Count(tblMain.Gender) AS CountOfGender
          FROM tblMain
          GROUP BY tblMain.Gender;
          The report has a txtMale & txtFemale box.

          Thanks!

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            Are you adding the counts to a new report or an exsisting one?

            * We should probabily split at this point given the question in OP appears to be answered.

            Comment

            • lyodmichael
              New Member
              • Jul 2012
              • 75

              #7
              hmm, do you try to seperate the 2 gender for two query? exp: select tblmain.gender count(tblmain.g ender) as ... where gender = "male,m,Mal e" . because when you use group, i think you can show the 2 fields .

              its just my advice,

              Comment

              • zmbd
                Recognized Expert Moderator Expert
                • Mar 2012
                • 5501

                #8
                lyodmichael
                I wasn't very clear... if artemetis is creating a new report then simply using the query as the record source will be fairly easy to do by simply assigning the control source of the text fields to the correct query fields in the detail section of the report. The wizard actually doesn't do a bad job of creating a very simple report.

                However, if artemetis is trying to add this information to an existing report then there are few hoops to jump thru to get the counts.

                *This is why I have asked the thread to be re-posted as a new question as this is a seperate issue from the OP

                -z

                Comment

                • artemetis
                  New Member
                  • Jul 2007
                  • 76

                  #9
                  Thanks folks.

                  ZMBD - I'm adding this to an existin report, which contains sub-reports.

                  Funny thing, when creating a "New Report" when using the SQL as a datasource, I'm able to get a report showing
                  F - 32
                  M - 40

                  As soon as I add a subform, the subform gets displayed twice with a genderCount as a header.

                  (feel free to split this thread as necessary)

                  Comment

                  • zmbd
                    Recognized Expert Moderator Expert
                    • Mar 2012
                    • 5501

                    #10
                    report formating

                    If you added the subform to the details section of the main form (or report) then yes, the subform will repeat for each of the grouped entries, in this case "m" and "f" so you get two... if you had "m", "f", and "h" you'd get three and so on.

                    If you need to get a count of the M and F to fall in the footer or header of the report there are several different ways to do that depending on how the report is bound to the record source and how it is layed out.. one way is to place a textbox in the header/footer of the form and set the control source of the text box so that you have something along the lines of
                    Code:
                    =Format(Count([ChangeToYourRSFieldName]),"Fixed")
                    and so forth.

                    -z

                    Comment

                    • artemetis
                      New Member
                      • Jul 2007
                      • 76

                      #11
                      My main report is bound to tblMain.
                      This tbl has empFirstName, empLastName, empGender

                      I have two text boxes in the header:
                      txtMaleCount and txtFemaleCount

                      I've tried several ways to get the counts into each text box, with no success. Zmbd's last respone^^^, second paragraph, is what I'm trying to do.

                      Thanks, in advance.

                      Comment

                      • Rabbit
                        Recognized Expert MVP
                        • Jan 2007
                        • 12517

                        #12
                        It may be simpler if you just used unbound textboxes and set the control source to a DCount().

                        Comment

                        • twinnyfo
                          Recognized Expert Moderator Specialist
                          • Nov 2011
                          • 3653

                          #13
                          If you wanted ultra simple, have a tiny subform linked tothe following query:

                          Code:
                          SELECT Sum(IIf([Gener]= "M",1,0)) AS Male, Sum(IIf([Gender] = "F",1,0)) AS Female
                          FROM tblYourTable;
                          Then the values would be updated every time..... I find having an unbound control that executes a DCount() often seems to really slow down the form.

                          Comment

                          • artemetis
                            New Member
                            • Jul 2007
                            • 76

                            #14
                            Thanks, Twinnyfo!
                            That did it!!!

                            Comment

                            Working...