Results 1 to 13 of 13
  1. #1
    Imbracer is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    6

    Post Unique dates query

    I live in a community where tenants can only use their lots for 180 days per year. We control access with a carded gate system. Each time a tenant uses their card to access the gait a log is created. I am able to import the log into Access. I need a query that will give me a total of unique dates that each tenant has accessed the gate. The two fields are "Name" and Date". I can query the table and get a count of all the times the gate was accessed but I only want to count each date once even though tenants may access the gait several times per day. I am not well versed with SQL so is there a simple solution to this problem?

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Perhaps you can create a Totals query. There is a sigma symbol at the top of the Query Designer, in the Ribbon. Create a Totals query and count your dates by changing the Group By to Count, within the Total row.

  3. #3
    Imbracer is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    6
    I have tried that but it returns the total number of times the gate is accessed. I need it to count each unique dates not every card transaction. Thanks for the suggestion.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Please post the SQL view of the query you are using.

    Name and Date are reserved words in msAccess.

  5. #5
    Imbracer is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    6
    This is an example of the table.

    Date Type Num name Action Event
    12/20/14 Cards 4635 CB-067 Admit EXIT GATE
    12/20/14 Cards 4635 CB-067 Admit ENTRY GATE
    12/19/14 Cards 4635 CB-067 Admit EXIT GATE
    12/18/14 Cards 4635 CB-067 Admit ENTRY GATE
    12/17/14 Cards 4635 CB-067 Admit EXIT GATE
    12/17/14 Cards 4635 CB-067 Admit ENTRY GATE
    12/15/14 Cards 4635 CB-067 Admit EXIT GATE
    12/14/14 Cards 4635 CB-067 Admit ENTRY GATE
    12/14/14 Cards 4635 CB-067 Admit EXIT GATE
    12/14/14 Cards 4635 CB-067 Admit ENTRY GATE

    a normal count query will return

    name Date
    CB-067 10

    i need it to return

    name Date
    CB-067 6

    counting only unique dates.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You can view the SQL from within the query designer. The view option is in the upper left hand corner.

  7. #7
    Imbracer is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    6
    This is the SQL from the query of the table.

    SELECT Count([2test].DATE) AS CountOfDATE, [2test].NAME
    FROM 2test
    GROUP BY [2test].NAME;

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Instead of counting NAME, you may want to count DATE. Also, after you create your count, add another field by dragging DATE to the grid.

    Another thing, as mentioned, change the name of your fields. Maybe, MyName and MyDate or GateDate and MemberName

  9. #9
    Imbracer is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    6
    I appreciate the thought but the field names are not the problem. When you run the above query I get this result:

    CountOfDATE NAME
    116 CB-000
    341 CB-001
    8 CB-002
    75 CB-003
    5 CB004
    The query counts every transaction on each day rather that only counting the day transactions occurred. I need a query to return a count of "unique dates".

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    OK, I think this problem is beyond my abilities.

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    You need to group by Date, also.

    I tested your data . I chose to modify Date format and rename fields and saved file as EntryInfo.

    Table for testing:
    Code:
    MDate MType Num Mname Action Event
    12/20/14 Cards 4635 CB-067 Admit EXIT_GATE
    12/20/14 Cards 4635 CB-067 Admit ENTRY_GATE
    12/19/14 Cards 4635 CB-067 Admit EXIT_GATE
    12/18/14 Cards 4635 CB-067 Admit ENTRY_GATE
    12/17/14 Cards 4635 CB-067 Admit EXIT_GATE
    12/17/14 Cards 4635 CB-067 Admit ENTRY_GATE
    12/15/14 Cards 4635 CB-067 Admit EXIT_GATE
    12/14/14 Cards 4635 CB-067 Admit ENTRY_GATE
    12/14/14 Cards 4635 CB-067 Admit EXIT_GATE
    12/14/14 Cards 4635 CB-067 Admit ENTRY_GATE
    SQL for query EntriesByDate
    Code:
    SELECT EntryInfo.Mname, EntryInfo.MDate
    FROM EntryInfo
    GROUP BY EntryInfo.Mname, EntryInfo.MDate;
    Result:
    Code:
    Mname MDate
    CB-067 14/12/2014
    CB-067 15/12/2014
    CB-067 17/12/2014
    CB-067 18/12/2014
    CB-067 19/12/2014
    CB-067 20/12/2014
    Then use the first query to get count.
    Code:
    SELECT EntriesByDate.Mname, Count(EntriesByDate.MDate) AS CountOfMDate
    FROM EntriesByDate
    GROUP BY EntriesByDate.Mname;
    Result -final:
    Code:
    Mname CountOfMDate
    CB-067 6
    Good luck.

  12. #12
    Imbracer is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    6
    Works great! You Rock!! Thanks!!!

  13. #13
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    You're welcome. Good luck with your project.

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

Similar Threads

  1. Replies: 5
    Last Post: 07-12-2014, 02:55 PM
  2. Replies: 22
    Last Post: 03-03-2013, 02:00 PM
  3. Unique queries - Unique Count
    By bigfish in forum Queries
    Replies: 7
    Last Post: 03-14-2012, 01:28 PM
  4. Query input dates for range of dates in two fields
    By kagoodwin13 in forum Queries
    Replies: 3
    Last Post: 02-13-2012, 04:25 PM
  5. query that will contain all unique records
    By halcolm1 in forum Queries
    Replies: 0
    Last Post: 01-19-2007, 05:34 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