Results 1 to 7 of 7
  1. #1
    Tac22 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2019
    Posts
    2

    Need a Custom PK

    Hello All,

    I'm fairly new to access and learning new things everyday...

    I'd like to create a Customer_ID private key for my Customer table. I'd like the Customer_ID in this format:



    -Last two digits of current year (when record is created)
    -First letter of Last_Name
    -Three digit autonumber

    Example: A new customer (J. Smith) is created in 2019. Custumer_ID = "19S001"

    I thought a composite PK was the way to go but, apparently you can't create a composite PK from calculated fields.

    Any help, suggestions, or advice would be welcomed.

    Thank you.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    why not just use Autonum as primary key in order to create child recs.
    and use your Custom field for internal office reference?

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    apparently you can't create a composite PK from calculated fields.
    you can't. Generally this approach is not a good one - at least for a primary key. Just use an autonumber primary key and create your calculated key in vba to update the record

    Not sure what the benefit is of your key. I presume the idea is that you are effectively limiting yourself to 999 customers per letter? or 999 in total? or 999 new customers per year?

    the year part is straight forward enough, but could just as easily be stored as an 'account opened' date which has the potential to be much more informative
    I have doubts about your letter - what if the company only has a one word name? or double barrelled name? or the spelling is such you can't determine the required letter - e.g. J.Smith, J. Smith, J Smith
    the autonumber part would be accomplished using what is commonly referred to as DMax+1

    I'll leave you to ponder - but to find the max number buried in a text string with (presumably) conditional requirements around year and letter for which max you want 18S?, 19S? 19T? is a lot more work

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    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,850
    Tac22,
    Spend some time reviewing database principles to get a good grasp of what the data base software can do for you. In my view your approach could be working against you. Too many new to database try to concoct coding schemes that end up as a mishmash that could have been prevented with the proven - 1 fact, 1 field approach.
    See links in my signature for helpful articles.
    Good luck with your learning activity.

  6. #6
    Tac22 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2019
    Posts
    2
    Great, practical advice from all. I had a feeling I was trying to over-engineer or over-complicate things. I suppose I just wanted a unique Customer_ID... something other than 001, 002, 003... I guess I don't have to make the Customer_ID the PK for the table though like ranman256 said. Thank you for the prompt replies. I'm glad I registered for an account here.

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    I guess I don't have to make the Customer_ID the PK for the table
    Not sure what that means. somethingID is usually associated with the PK of a table, and is often but not always simply an autonumber field. The only real purpose of that is to virtually guarantee that no 2 records will have the same value. Hopefully you got that from the PK links I posted. Don't confuse what I'm saying with the desire (and often wise choice) to have a meaningful value that identifies the customer via some value such as their name, and to make that a unique index - as long as you know there will never be 2 Acme companies. My former employer designed around that potential by making an abbreviated customer value as the unique constraint. Thus if there could be 2 or more "Smith and Sons Enterprises" one got SmithSonsEnt and the other SmithSonsEnterp or something like that. Maybe that's a bad example, but I can tell you there were a few duplicates.

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

Similar Threads

  1. About Custom ID
    By notrino in forum Access
    Replies: 1
    Last Post: 12-16-2018, 03:28 PM
  2. Custom Icon
    By Cazca in forum Access
    Replies: 0
    Last Post: 02-12-2016, 06:18 PM
  3. Replies: 2
    Last Post: 05-27-2014, 11:32 AM
  4. Custom Autonumbering
    By mguardab in forum Access
    Replies: 1
    Last Post: 05-22-2014, 12:02 PM
  5. Custom warning
    By janelgirl in forum Forms
    Replies: 4
    Last Post: 05-04-2011, 01:56 PM

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