Results 1 to 10 of 10
  1. #1
    vianda is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    6

    Trying to label each date with same number from 1 to 5. Repeat until lis ends

    Hi, I'm trying to make a query, that will put a number in field “Date #” for each date occurrence, from number 1 to 5
    (same # to same dates). I’m not sure if I have explained this clear, so I added a picture of what I want to be returned in the “Date #” field.



    Thanks

    Query1
    Provider'sName Child'sName Date Date #
    Jane Smith HITZGES, AYLA 6/1/2016 1
    Jane Smith BREEN, FIONA 6/1/2016 1
    Jane Smith Grundner Jayden 6/1/2016 1
    Jane Smith WILDING, CONNOR 6/2/2016 2
    Jane Smith CLINTON, BROOKLYN 6/2/2016 2
    Jane Smith BREEN, FIONA 6/3/2016 3
    Jane Smith PLETO, LANDON 6/3/2016 3
    Jane Smith WILDING, CONNOR 6/3/2016 3
    Jane Smith Boos Ethan 6/6/2016 4
    Jane Smith BREEN, FIONA 6/6/2016 4
    Jane Smith HITZGES, AYLA 6/6/2016 4
    Jane Smith Grundner Jayden 6/6/2016 4
    Jane Smith RICE, GRADY 6/6/2016 4
    Jane Smith WILDING, CONNOR 6/6/2016 4
    Jane Smith Gross Oliver 6/6/2016 4
    Jane Smith Melton Garrett 6/7/2016 5
    Jane Smith DEARING, KAYLEE 6/7/2016 5
    Jane Smith DEARING, KAYLEE 6/7/2016 5
    Jane Smith CLINTON, BROOKLYN 6/7/2016 5
    Jane Smith HITZGES, AYLA 6/7/2016 5
    Jane Smith WILDING, CONNOR 6/7/2016 5
    Jane Smith Grundner Jayden 6/8/2016 1
    Jane Smith HITZGES, AYLA 6/8/2016 1
    Jane Smith RICE, GRADY 6/8/2016 1
    Jane Smith BREEN, FIONA 6/8/2016 1
    Jane Smith HITZGES, AYLA 6/8/2016 1
    Jane Smith DEARING, KAYLEE 6/9/2016 2
    Jane Smith Grundner Jayden 6/9/2016 2
    Jane Smith Boos Ethan 6/9/2016 2
    Jane Smith BREEN, FIONA 6/10/2016 3
    Jane Smith WILDING, CONNOR 6/10/2016 3

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    As far as I'm concerned, it is only possible with code. Before going down that route, are you absolutely certain that this is a requirement, or would you care to provide the reason? Maybe there is another way.
    BTW, you should not use special characters (e.g. # or ') or reserved names (e.g. Date)
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Apr 2017
    Posts
    1,776
    On fly
    Code:
    SELECT yt.*, Int(((SELECT COUNT(dc.DateField) FROM YourTable dc WHERE dc.ProvidersName = yt.ProvidersName AND dc.DateField <= yt.DateField) -1)/5) AS DateNo FROM YourTable yt
    NB! I changed field names in query, and I advice you do same with your tables/queries:
    Date is reserved word in Access (and in most other databases too) - you never can be sure how Access reacts on it;
    Don't use nothing except letters, numbers and "_" in field names. Access can interpret other characters (like "'" or "#") in his own way.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Tested the query and getting count of 0, 1, 2, 4, 5, 6
    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
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    think you need something like

    SELECT yt.*, (((SELECT COUNT(DateField) FROM (SELECT DISTINCT Datefield FROM YourTable) dc WHERE dc.DateField <= yt.DateField)-1) MOD 5)+1 AS DateNo FROM YourTable yt

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Fantastic! That works.
    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
    Join Date
    Apr 2017
    Posts
    1,776
    OK. I forgot that on same date are several entries at first.

    Create a saved query p.e.
    Code:
    SELECT DISTINCT ProvidersName, DateField FROM YourTable;
    Now the query will be:
    Code:
    SELECT yt.*, (((SELECT COUNT(pd.DateField) FROM qProviderDates pd WHERE pd.ProvidersName = yt.ProvidersName AND pd.DateField <= yt.DateField)-1)/5 - Int(((SELECT COUNT(pd.DateField) FROM qProviderDates pd WHERE pd.ProvidersName = yt.ProvidersName AND pd.DateField <= yt.DateField)-1)/5))*5 + 1 AS DateNo FROM YourTable yt
    Edit. I see Ajax got simpler solution!

  8. #8
    vianda is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    6
    Thank you for the help. I did write your solution and I get an error 'Syntax Error in Join Operation' highlighting "MOD". Also I used
    /5))*5 (ArviLaanemets)
    Same error
    highlighting "/". I'm Stuck

    SELECT UNITSbyDATE.[Provider'sName], UNITSbyDATE.[Child'sName], UNITSbyDATE.DateField, UNITSbyDATE.Units, UNITSbyDATE.Rate, UNITSbyDATE.DateNumber
    FROM UNITSbyDATE,
    (((SELECT COUNT(DateField) FROM (SELECT DISTINCT Datefield FROM UNITSbyDATE) dc WHERE dc.DateField <= UNITSbyDATE.DateField)-1) MOD 5)+1 AS DateNo FROM UNITSbyDATE

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Can't have two FROM clauses in the outer query.

    Ajax's suggestion works. Have to use the yt table alias.

    SELECT yt.*, (((SELECT COUNT(DateField) FROM (SELECT DISTINCT Datefield FROM UNITSbyDATE) dc WHERE dc.DateField <= yt.DateField)-1) MOD 5)+1 AS DateNo FROM UNITSbyDATE yt;
    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.

  10. #10
    vianda is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    6
    Thank You to everyone who help, It works great!

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

Similar Threads

  1. Replies: 3
    Last Post: 11-01-2016, 03:46 PM
  2. records number shows in label
    By mathanraj76 in forum Programming
    Replies: 3
    Last Post: 04-24-2013, 07:37 PM
  3. Replies: 30
    Last Post: 08-15-2012, 02:25 PM
  4. Replies: 8
    Last Post: 01-19-2011, 04:48 AM
  5. Replies: 2
    Last Post: 02-20-2010, 01:11 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