Results 1 to 6 of 6
  1. #1
    Annita is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    3

    Adding an Id to a table

    Hi all,

    I have a problem. I would like to add an Id to a table that I have with Names and Dates. The names and dates are ordered but I would like to add a number using a query, but I don't know how. Can you please help me?

    What I have:




    What I need:


    Many thanks!!!!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Generally this isn't the type of thing you want to save in a table, since it will change. I assume that when Peter comes/calls again the new record will be number 1, and the existing number 1 becomes 2, etc.

    On a report you could use the Running Sum property to achieve this. In a query, you'd either use DCount() or a subquery. With either, you'd have a criteria that matched the name and counted dates greater than or equal to the current record.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    You're not adding an ID you're just adding a sequential number to each group of data (in your case names sorted by dates in descending order). Can I ask why you want to do this in a table? As Pbaldy pointed out if you intend, the next time peter has a record to assign it a value of 1 and increment all his existing records by 1 is an extremely cumbersome way to handle your data. If you can explain what you're trying to do as an end result we may be able to offer a better solution.

  4. #4
    Annita is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    3
    Got the solution from another forum, but just in case anyone else needs it...

    Code:
    SELECT Name_c, Date_Id, DCount("Name_c","myTable","[Name_c]='" & [Name_c] & "' AND [Date_Id]<=#" & Format([Date_Id],"mm/dd/yyyy") & "#") AS Num_by_Name
    FROM myTable

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Looks a lot like:

    Quote Originally Posted by pbaldy View Post
    In a query, you'd...use DCount()....you'd have a criteria that matched the name and counted dates greater than or equal to the current record.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Annita is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    3
    Yeah! Thanks pbaldy, but I needed some example code

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

Similar Threads

  1. Adding Textbox value into Table
    By sikhinvestor in forum Access
    Replies: 2
    Last Post: 06-05-2014, 07:29 AM
  2. Adding data to a table
    By Jbelle7435 in forum Programming
    Replies: 17
    Last Post: 06-13-2011, 07:30 AM
  3. Adding a record not found in another table.
    By Buakaw in forum Queries
    Replies: 1
    Last Post: 03-03-2011, 05:38 AM
  4. Replies: 1
    Last Post: 10-09-2009, 11:52 AM
  5. Adding a table cannot enter data
    By tak4 in forum Queries
    Replies: 0
    Last Post: 02-03-2009, 10:04 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