Results 1 to 2 of 2
  1. #1
    Koala is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2011
    Posts
    1

    Auto-incrementing number that starts over

    Hi all, this is my first post here. I ran into an interesting problem that I need a solution to.



    I have a table, Purchases, which has a 1:N relationship with another table, Items. Each purchase can have multiple Items.

    'PurchaseID' is the primary key of my Purchases table.



    The Items table has a composite primary key, made up of PurchaseID (making it an identifying relationship) and ItemID.



    As you can see, I have ItemID starting reverting back to 1 each time PurchaseID increments. PurchaseID is an autonumber on the Purchases table, however ItemID is just a Number and has to be entered manually. If I set ItemID to an autonumber, it will continue to increment even after PurchaseID changes.

    What I am trying to do is to get ItemID to auto-increment but revert back to 1 each time PurchaseID increments.

    The entry form for both looks like this:



    The Record Source of the main form is the Purchases table, and the subform is a Multiple Items Form based on the Items table. Filling out the form will create a new Purchase record with an auto-incremented PurchaseID, and a number of new Item records with that same PurchaseID, and whatever ItemID's are specified in the subform. Currently the ItemID's have to be entered manually as 1, 2, 3, etc.

    Is there a way to get them to auto-increment, but begin from 1 for each new Purchase record?

    Much thanks to all who can help me solve this.

  2. #2
    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,847
    Just curious why do you need an item number as such.
    What if the "things" that were Purchased were Products and these Products had separate ProductNumbers or IDs? You would have them on your Purchase (Order) and they would be line items, but they wouldn't be numbered 1,2,3....

    I can't think of any way to do that with an autonumber.
    But you could have reference variable. Set the value of this refNo to 0.
    When you add an Item increment the refNo by 1.
    When you open a new PurchaseOrder set the refNo back to 0.

    If it's only for counting or to get NumberOfItems, you could do that with DCount() and a filter.

    Just my quick $.02

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

Similar Threads

  1. Replies: 4
    Last Post: 07-27-2011, 09:25 AM
  2. Replies: 1
    Last Post: 07-27-2011, 09:19 AM
  3. AuTo NuMbEr
    By Evgeny in forum Forms
    Replies: 2
    Last Post: 04-25-2010, 04:23 AM
  4. Auto-number
    By rkski in forum Programming
    Replies: 2
    Last Post: 01-13-2010, 02:04 AM
  5. Custom & Auto Incrementing Job Number
    By mastromb in forum Programming
    Replies: 1
    Last Post: 01-05-2010, 02:58 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