Results 1 to 5 of 5
  1. #1
    imran688 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    30

    Controlling Autonumber field - Start autonumber from 1 everyday (Composite Key)

    Hello,


    I have two tables linked to each other in one to many relationship. Instead of auto number, the date and shift (Text) is being used as the primary keys (Composite Primary Key). Here is the tables structures,

    Payouts Table:
    Date: Primary Key
    Shift (Day or Night) : Primary Key

    Bills Table:
    Date: Primary Key
    Shift (Day or Night): Primary Key
    Autonumber: Primary Key

    The tables Payouts and Bills has one to many relationship. One payout row can have many bills. The problem is that I want to start the Autonumber in bills table everyday from 1. As date and shift are different for every day so even if i start bills from 1 everyday, it wont make same primary key. I can do it manually but I want to make it automatically. Please help me out how to do it.

    Thanks,
    Imran

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    I don't think an autonumber field can be forced to work that way. Use a number field and programatically manage the sequencing.
    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
    imran688 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    30
    How to make manage it programatically. Can you post some code?? thanks

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    This requires code that will look up the most recent sequence number for given criteria and then increment. I do this to create a unique identifier. The code creates the ID then immediately saves it to a record to minimize possibility of multiple users generating the same number. It's only happened once.

    Review https://www.accessforums.net/forms/a...ing-23329.html
    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
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

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

Similar Threads

  1. Composite key or autonumber PK
    By Liam87 in forum Access
    Replies: 4
    Last Post: 11-06-2012, 07:39 PM
  2. Replies: 2
    Last Post: 03-05-2011, 05:26 PM
  3. Manually autonumber a field
    By apsf68 in forum Access
    Replies: 15
    Last Post: 11-13-2010, 04:04 PM
  4. Replies: 3
    Last Post: 08-09-2010, 08:02 PM
  5. Controlling autonumber
    By Patience in forum Access
    Replies: 3
    Last Post: 06-22-2010, 04:11 AM

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