Reputation: 9268
I am new in microsoft access. I was just wondering on how can I use create a custom primary key? for example abc-123 format?
Upvotes: 0
Views: 8113
Reputation: 49049
Actually, you could create a table trigger if using 2010 or later. The table trigger could take some field (where you get the abc from) and then some other field (seq num) and then add + 1 to the value.
The "air" code would look like this:
The beauty of the table trigger is it runs at table (data engine) level, and thus if you open the database with ODBC, VB.net, FoxPro, Access etc. then the PK key will always auto generate for you.
Upvotes: 2
Reputation: 36431
It depends on how you want the abc-123
values to be created.
If you want to create them by yourself in your code, just create a Text
column and use that as your primary key.
If you want Access to create these values...that's not really possible. The only thing that Access is able to auto-generate are increasing numerical values (data type AutoNumber
).
So the best thing you can do is to use an AutoNumber
internally as the actual primary key, and create the abc-123
value out of that, just for displaying.
Here are some examples how to do this, from previous similar questions that I answered in the past:
Disclaimer: I don't know if a similar approach would work in your case.
If not, you need to give more information how exactly you want your numbers to be created:
Upvotes: 2