Count IF on MS Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nasher
    New Member
    • Feb 2008
    • 7

    Count IF on MS Access

    How do you create a field on a form that counts the selected records, only if a certain word is in the field.

    Records are selected via a combo box on a form header.
    I then have tabs below that display different subforms.(One of the tabs is orders)

    Basically i have combo box on the orders form that lists all posible locations for a particular item e.g.
    "location 1 - sub location 1"
    "location 1 - sub location 2"
    "location 2 - sub location 1"
    "location 2 - sub location 2"

    i want to count all the records that have "location 1" at the start and display the quantity in a field on the orders form
    Last edited by Nasher; Feb 11 '08, 02:13 PM. Reason: adding further explination
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by Nasher
    How do you create a field on a form that counts the selected records, only if a certain word is in the field.

    Records are selected via a combo box on a form header.
    I then have tabs below that display different subforms.(One of the tabs is orders)

    Basically i have combo box on the orders form that lists all posible locations for a particular item e.g.
    "location 1 - sub location 1"
    "location 1 - sub location 2"
    "location 2 - sub location 1"
    "location 2 - sub location 2"

    i want to count all the records that have "location 1" at the start and display the quantity in a field on the orders form
    This would be the general idea:
    [CODE=vb]
    Me![txtQuantity] = DCount("*", "<Your Table Name>", "Left([<Location Field>], 10) = 'Location 1'")[/CODE]

    Comment

    • Nasher
      New Member
      • Feb 2008
      • 7

      #3
      Originally posted by ADezii
      This would be the general idea:
      [CODE=vb]
      Me![txtQuantity] = DCount("*", "<Your Table Name>", "Left([<Location Field>], 10) = 'Location 1'")[/CODE]
      Cheers for the quick response ADezii.

      I've been trying to get that code to work but unfortunatly i'm not very good when it comes to visual basic and i haven't been successful yet.

      Can you give me step by step instructions, or is their another way of doing it e.g. expression builder or a query

      P.S. forgive me if i sound stupid, but i am!

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by Nasher
        Cheers for the quick response ADezii.

        I've been trying to get that code to work but unfortunatly i'm not very good when it comes to visual basic and i haven't been successful yet.

        Can you give me step by step instructions, or is their another way of doing it e.g. expression builder or a query

        P.S. forgive me if i sound stupid, but i am!
        I'll need your Table Name, Location Field Name in the Table, and the Location Field Name on the Form, and the Quantity Field Name.

        Comment

        • Nasher
          New Member
          • Feb 2008
          • 7

          #5
          Originally posted by ADezii
          I'll need your Table Name, Location Field Name in the Table, and the Location Field Name on the Form, and the Quantity Field Name.
          Table name is "Scaling", field name in the table is "Location Name", field name on the form is "Location Name" and the quantity field name is "Quantity"

          Cheers for the help ADezii

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by Nasher
            Table name is "Scaling", field name in the table is "Location Name", field name on the form is "Location Name" and the quantity field name is "Quantity"

            Cheers for the help ADezii
            Try:
            [CODE=vb]
            Me![Quantity] = DCount("*", "Scaling", "Left([Location Name], 10) = '" & Me![Location Name] & "'")[/CODE]

            Comment

            Working...