Add Soldiers who are promotable only =Count (IIf[x]="y" and [z]="a")

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lucas Schwartz
    New Member
    • Jan 2011
    • 15

    Add Soldiers who are promotable only =Count (IIf[x]="y" and [z]="a")

    I need to do something like

    =Count(IIf([Rank]="SPC" and [Promotable]=-1 )

    I also need to do

    =Count(IIf([Rank]="SPC" and [WLC]=-1 )

    Promotable is a Check box
    Rank is an exact selection from a drop down box.
    I'm assuming that -1 = the box is checked. Im new to reports in access Thanks
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    Lucas,

    How messy do you want your nested queries to be? I'd suggest using two queries, just to make life simple. The first would be:
    Code:
    SELECT COUNT(*)
      FROM soldier AS ss
      WHERE (ss.Rank = "SPC")
            AND ([Promotable]=-1);

    And the second:
    Code:
    SELECT COUNT(*)
      FROM soldier AS ss
      WHERE (ss.Rank = "SPC")
            AND (ss.WLC = -1);

    If they absolutely have to be in one query, we can go into that, too.

    Good Luck!
    Oralloy
    Last edited by Oralloy; Jan 10 '11, 06:04 PM. Reason: Change "Promotable" from SQL to parameter.

    Comment

    • Lucas Schwartz
      New Member
      • Jan 2011
      • 15

      #3
      I need it to display in a report i was using unbound text boxes to do this. Can i still do this with the method above and how would i insert it? I have made a report that hides all the soldiers information and is one page that displays all the stats i want like the count of each rank of soldiers using :=Count(IIf([Rank]="PV1",0)) ext

      Comment

      • Lucas Schwartz
        New Member
        • Jan 2011
        • 15

        #4
        I should have specified it was for an report

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          Use the DCount function.

          Comment

          • Lucas Schwartz
            New Member
            • Jan 2011
            • 15

            #6
            Ill research it never heard of it. Hope its easy! lol

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              Pretty easy, DCount("fieldna me", "table name", "where condition").

              Fieldname can be "*" and the where condition is optional.

              Comment

              • Oralloy
                Recognized Expert Contributor
                • Jun 2010
                • 988

                #8
                Rabbit, thanks. I keep forgetting to use the DCount() function.

                Lucas, Luck!

                Comment

                • Lucas Schwartz
                  New Member
                  • Jan 2011
                  • 15

                  #9
                  I'm confused on how to evaluate two items from one record using this:
                  =DCount("WLC",P ersonnel Data", ?

                  I need it to Display all that are checked WLC and = "SPC" in rank field

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    Well, I think it was just a miscommunicatio n from the first post. If it was in SQL, I wouldn't use DCount either, but if he's trying to use an unbound textbox in a form, then that's one of the few situations when I would settle for DCount.

                    Comment

                    • Lucas Schwartz
                      New Member
                      • Jan 2011
                      • 15

                      #11
                      =DCount([WLC],"Personnel Data","WLC=-1") returned 42 entires so i got that part but now i need to make it just show records that WLC is checked and the rank = "SPC"

                      Comment

                      • Oralloy
                        Recognized Expert Contributor
                        • Jun 2010
                        • 988

                        #12
                        Try: =DCount([WLC],"Personnel Data","(WLC=-1) AND Rank='SPC'")

                        Comment

                        • Lucas Schwartz
                          New Member
                          • Jan 2011
                          • 15

                          #13
                          How would i modify this to add say
                          =SPC & WLC checked & promotable is checked?

                          Comment

                          • Oralloy
                            Recognized Expert Contributor
                            • Jun 2010
                            • 988

                            #14
                            Pretty much exactly the way you wrote it.

                            Try: =DCount([WLC],"Personnel Data","(Rank = 'SPC') AND (WLC = -1) AND (promotable = -1)")

                            Comment

                            • Lucas Schwartz
                              New Member
                              • Jan 2011
                              • 15

                              #15
                              ah ok got it! What does the first part [WLC] represent?

                              Comment

                              Working...