Results 1 to 5 of 5
  1. #1
    rbremer is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Location
    Arlington, VA
    Posts
    3

    sequential count field in query by Id

    I need to create the gift counter field in a query field that counts the number of gifts by Id and starts over when it detects a new ID. The ID and gift_date fields are already sorted in ascending order. I have experimented with DCount. This has proven not to work Nz(DCount("*","All_Gifts","[Constituent ID] <= " & [Constituent ID]),0)+1 I would prefer to do this as a field within the same query rather than have to create another query and join it back since the dataset is large. These are the results I am looking for:



    Constituent ID Gift_date Gift_counter
    1112 3/15/2015 1
    1112 4/15/2015 2
    1112 5/15/2015 3
    1225 1/12/2015 1
    1225 2/15/2015 2
    1225 3/15/2015 3
    1225 4/15/2015 4
    1381 2/15/2015 1
    1381 3/15/2015 2

    Thank you

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    You want to rank records by group. This is not easy in query or form. Textbox in report has RunningSum property so can be done in report with little effort.

    DCount() Is one method. You need the Gift_date field in the expression.

    DCount("*", "All_Gifts", "[Constituent ID] = " & [Constituent ID] & " AND Gift_date <#" & [Gift_date] & "#") + 1

    Also nested subquery http://allenbrowne.com/ranking.html

    Either way, such queries can be slow performers.
    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
    rbremer is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Location
    Arlington, VA
    Posts
    3
    Thanks for the feedback, but pasting this formula in to my query results in an #Error message for every row.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Make sure field names in the expression are spelled correctly. If [Constituent ID] does not have a space, remove it.

    Otherwise, it works for me.
    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
    rbremer is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Location
    Arlington, VA
    Posts
    3
    You're right, it does work if you are not trying to sort the Constituent ID and gift_date variables within the same query. However, I tried it on a sample of 1000 records and it ran too slow. I need it to run on 30,000 records, so I think I will try it in a report instead. Thanks for your help.

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. Count Field in a different query
    By sam.eade in forum Queries
    Replies: 5
    Last Post: 05-08-2014, 10:31 AM
  3. Replies: 4
    Last Post: 07-28-2013, 12:40 AM
  4. Replies: 4
    Last Post: 01-03-2013, 08:29 PM
  5. Replies: 3
    Last Post: 10-18-2009, 08:38 PM

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