Results 1 to 12 of 12
  1. #1
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376

    Primary Key Numbers

    I want to be able to format the primary key field to display 4 numbers, ie., display 0001 instead of 1, 0002 instead of 2 etc., is there a way I can do this and still leave the field as auto number?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Why? What rationale do you have for formatting the PK for display?
    You can always reformat something for certain purposes eg CStr, CDate etc or Format().
    Primary key is meant for the DBMS, not the client/user per se.

    Good luck

  3. #3
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    I want to display it because the form it represents is formatted that way. It is just easier than creating a new column with essentially the same number.

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    In no time at all you will reach the 9999 limit. NEVER use autonumber fields to have meaning. You'll find that it isn't that much extra work to create an extra field under your control.

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    In another thread, ssanfu displays this link to how to use autonumbers.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

  7. #7
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    Here is my problem, this is the number I am working with, 50-09-0001, the 50-09 is a constant, the last 4 digits increment with every new instance of a document, it will take literally years to reach 50-09-9999 so that doesn't concern me. The table I currently have (imported from an Excel file) has a standard primary key of 1,2,3 etc that matches the last 4 digits (1 =50-09-0001, 150=50-09-0150, etc). I have entered a new field like others have suggested but I don't know how to add the leading "0's".

    I then would like to have this field automatically populated based on the primary key #. Does that make sense?

    Your help and guidance is greatly appreciated.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Not really. 50-09-0001 is not a number. I would call it a custom code made up of a dash and digits. It is composed of 2 or 3 parts separated by "-"(dash). It means something to you and others in your organization. Too many people attempt to put too much intelligence into their custom codes.
    Most designers would advise you to use atomic fields. That is fields that have a single fact in each field eg. Firstname, Lastname rather than CustomerName composed of both First and Last name.

    You can create a "sequence" (incremental numeric values) using DMax(current value) +1.

    I suggest you research Dmax() +1 and if you really need the code, then add your prefix (a string "50-09") to a formatted Dmax() + 1
    for the code. You will need to format the number to get your leading 0's, and format will result in a string.
    Iwould use a separate autonumber field as PK. Others may have a different view.

    Good luck.

  9. #9
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    Orange,

    Your are correct, my mistake, it is a document number and only the last 4 digits are what I am concerned with, they are significant and sequential, each new document has a different 4 digit ending. I will take a look at what you suggest, it seems like it should work great, I just have to figure out how to do it, thanks for the suggestion.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Paul has a good description here: http://www.baldyweb.com/CustomAutonumber.htm

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Dave,

    Attached is an article that may put some thoughts/concepts/approaches into context.
    It has been referenced by others in the past, and I think it is well done.

    Good luck.
    Attached Files Attached Files

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

Similar Threads

  1. Replies: 5
    Last Post: 10-29-2014, 12:12 PM
  2. Replies: 6
    Last Post: 04-28-2014, 12:41 PM
  3. Replies: 8
    Last Post: 03-10-2014, 11:47 AM
  4. same numbers = differnet numbers?
    By mike02 in forum Queries
    Replies: 1
    Last Post: 07-17-2013, 03:40 PM
  5. Replies: 1
    Last Post: 11-29-2011, 08:43 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