Results 1 to 5 of 5
  1. #1
    Srin is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    59

    Criteria to count the data in fields in table or Query

    I have a table with fields for Products of each type. Ex Product1, Product2, Product3 as fields. And another Field called Product Count in my table. I want the Count field to have a value of 1 as default and either 2 or 3 based on the result of all or some of the Product1,2,3 fields having values in the records.
    Ex:


    Product1 Product2 Product3 Count
    xxxx 1
    xxxx xxxx 2
    xxxx xxxx xxxx 3

    I want to state that there will be by default atleast one order. Hence the possibility of 0 orders is not there. Which is the right way to achieve this result?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    The 'right' way is to normalize data structure and then do either: aggregate (GROUP BY) Totals queries or build report using its Sorting & Grouping feature with aggregate calcs in footer sections.

    Otherwise, use IIf().

    IIf(Product1 Is Null, 0, 1) + IIf(Product2 Is Null, 0, 1) + IIf(Product3 Is Null, 0, 1)
    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
    Srin is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    59
    Where can I include this criteria to fill up the Count field? Will that be in a query as an Expression? Or can I do it in a table?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    Try a calculated field in table. See if it recognizes the IIf() function. Otherwise, do in query or textbox.
    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
    Srin is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    59
    It worked perfectly in a query. Thanks @June7!!

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

Similar Threads

  1. Query with criteria without field from table
    By macattack03 in forum Queries
    Replies: 3
    Last Post: 11-03-2013, 05:54 PM
  2. Delete Query - Use Another Table As Criteria
    By Madmartigan in forum Access
    Replies: 4
    Last Post: 07-12-2013, 01:15 PM
  3. Running Query on only 1 row of table.. Criteria?
    By JMac in forum Database Design
    Replies: 5
    Last Post: 04-16-2012, 11:27 PM
  4. query criteria read from table
    By drewetzel in forum Access
    Replies: 8
    Last Post: 12-07-2011, 11:01 AM
  5. Query Criteria from another table?
    By gmontano in forum Queries
    Replies: 1
    Last Post: 08-30-2010, 11:51 AM

Tags for this Thread

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