Results 1 to 2 of 2
  1. #1
    ChiSoxFan is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Mar 2014
    Posts
    1

    Group Consecutive Numbers in a Range

    Hello,

    Looking for a way to group consecutive numbers in a range.

    Here is a some sample data from a table (tblYears)

    Id Year
    smith01 2003
    smith01 2004
    smith01 2005
    smith01 2006
    jones01 2004
    jones01 2005
    jones01 2007
    jones01 2009
    davis01 2006



    If possible, I would like a query that would return the following:
    Id Years
    smith01 2003-2006
    jones01 2004-2005, 2007, 2009
    davis01 2006

    I am open to any suggestions, as I have no idea where to start. Can this be done with a query only, do I need a temp table?


    Thanks,
    ChiSoxFan

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    The only way I can envision doing something like that is to sort the data in a query, use VBA and Recordsets (i.e. DAO) to loop through the data row-by-row, and write the results out to a new table.

    So to answer your question, I think you will need VBA and a new table.

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

Similar Threads

  1. Count Consecutive Only
    By WickidWe in forum Queries
    Replies: 13
    Last Post: 12-16-2013, 02:33 AM
  2. Generating Range of numbers
    By frikkie in forum Access
    Replies: 1
    Last Post: 07-27-2013, 10:46 AM
  3. Replies: 1
    Last Post: 05-17-2013, 01:50 AM
  4. Consecutive ID numbers
    By jdvd in forum Database Design
    Replies: 2
    Last Post: 12-11-2011, 06:48 PM
  5. group by a range of values
    By therzakid in forum Queries
    Replies: 3
    Last Post: 07-24-2011, 02:22 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