Results 1 to 4 of 4
  1. #1
    tomazm71 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    10

    When no results from query then insert value 0.

    Hi,



    I'm trying to find a way to set the query which will show me the default 0 when there is no records from in one column. This column has a total Count included.

    I know Nz function but it turns zero when there is NULL result and I don't have any records.

    What are the other options? Is there a function that can show me the values 0?

    Let's assume there is a column called Actors and there are years Years when they were nominated for Oscars

    Smiths - 2006
    Smiths - 2007
    Stallonee - 2008
    Seagalll - 2009

    We have 2010 now and There are 5 nominees, we count how many times they were nominated

    Smiths - 2
    Stallonee - 1
    Seagalll - 1

    The question is how do I get Shfwarzeneeger to be shown if the count will not give me any results?

    Thanks in advance.
    Tom

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,144
    You need a sub query or second query to get your actor and count, and left join that to your list of all actors.
    Then you use the NZ(CountofNominations,0) to provide the missing zero's
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    tomazm71 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    10
    Minty,

    Thanks very much for your help. It has helped and actually even the Nz was not neccessary. The query below showed me 0 for Shfwarzeneeger.

    SELECT Count(TblActors.YearNominated) AS CountOfYearNominated, TblNominee2010.Nominee2010
    FROM TblNominee2010 LEFT JOIN TblActors ON TblNominee2010.[Nominee2010] = TblActors.[Actor]
    GROUP BY TblNominee2010.Nominee2010;

    Tom
    *

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,144
    You might want to group on TblActors.[Actor] rather than the nominees.
    I suspect you'll miss some actors otherwise.

    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Replies: 3
    Last Post: 09-25-2018, 11:37 AM
  2. INSERT query: insert new data only
    By drh in forum Access
    Replies: 2
    Last Post: 04-04-2014, 05:31 PM
  3. Insert Pass-Through Results into Access Table with VB
    By raynman1972 in forum Programming
    Replies: 3
    Last Post: 06-20-2012, 08:43 PM
  4. Replies: 6
    Last Post: 05-14-2012, 07:24 AM
  5. Replies: 0
    Last Post: 02-24-2010, 12:56 AM

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