Results 1 to 11 of 11
  1. #1
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91

    show a 0 if there is nothing to count in a query

    Hi all,

    I'm using a query to count cases on a day. It could hapen that on that day there are no cases or the day is not yet (like running the query today and getting a 0 for tomorrow Friday)


    I'm using this SQL:
    Code:
    SELECT Count(tbl_Reviews_case_list.[Case Status]) As [On Hold Tuesday] 
    FROM tbl_Reviews_case_list 
    GROUP BY tbl_Reviews_case_list.[Case Status] 
    HAVING (((tbl_Reviews_case_list.[Case Status])="On hold") And ((Count(tbl_Reviews_case_list.[On Hold (date)]))<#8/18/2015#));
    The date is now hard coded, but, this will be changed later.

    Greetings.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,523
    what if you put it in a field and the count converting to zero

    txtBox = NZ(dcount("*","qsCountQry"))

  3. #3
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    Hi Ranman,

    I'm using it actually only in a query to create the SQL to use it in Excel vba
    it is a long story :-(
    I have a report that uses over 5000 cells full of formulas and wanted to pull the data straight from access database.

    Greetings.

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,523
    then import the data, then get the line count.

  5. #5
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    Hi Ranman,

    My knowledge is not the greatest and it is kind of trying to do magic. The connections sometimes fails and most of the time all goes very slow (I have only so far 5 queries working, so it should be not that slow)
    I tried to make the report in access, but then, it is hard to get the same layout as I could in excel and it easier to place thing on a grid than the report layout from access.

    Or maybe I'm just wrong and access could do a better job?

    Greetings.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    If there is no data then there is nothing to count, can't even show 0.

    This would require a dataset of all possible date/status pairs then join that dataset to the primary raw dataset - join type "Show all records from date/status dataset and only those from raw dataset that match".
    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.

  7. #7
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    Hi June7,
    The second part I don't get. You mean to create the complete report I would need a lot of data connected let's say in a query and then query that data?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    If I understand your question - yes, two queries.

    Creating the dataset of all possible date/status pairs might be possible with a Cartesian query. A Cartesian query is a query without a JOIN clause - every record of a table will be associated with every record of another table. This would require a data source that has a record for every date and a data source of all status values.

    SELECT DISTINCT [date field], Status FROM [date field table], [status table];

    If you don't have a table that has at least one record for every date, this won't work.
    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.

  9. #9
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    Hi June7,
    sounds kind of daunting, no clue if I will be up to the job.
    I will maybe first get the data into excel book and use there the sql, maybe the connection will be much faster. I still need to figure out how it will work and need to look on many different ways. It will take me still some days before I have reasearched everything.

    Greetings.

  10. #10
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    Hi all,

    I solved by using vba to first get all the data into the workbook, and then with vba I run a autofilter with criteria (one criteria that takes date from a cell).
    Then there I use the "Application.WorksheetFunction.Subtotal" and this one give me the count I need.

    It works really fast and I only need to pull once the whole data in to get it done :-)

    Greetings.

  11. #11
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    I forgot to say that it also gives me '0' if there is nothing to count :-)

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

Similar Threads

  1. Replies: 3
    Last Post: 01-04-2015, 03:00 PM
  2. Show Record Count
    By mikej2505 in forum Forms
    Replies: 2
    Last Post: 06-23-2014, 10:35 AM
  3. Show Blanks in count as 0
    By WickidWe in forum Queries
    Replies: 2
    Last Post: 12-11-2013, 01:37 PM
  4. Show Count from different Zip Codes
    By jo15765 in forum Queries
    Replies: 6
    Last Post: 04-15-2013, 12:36 PM
  5. Replies: 1
    Last Post: 01-24-2011, 03:03 PM

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