Concatenate Fields to Create Primary Key

kathleen

Active Member
Joined
Dec 16, 2002
Messages
295
I am setting up a table to maintain Bill of Materials. I am in a headquarters environment so I am setting it up for multiple entities. There is a possibility that I can have the same Raw Material being used at multiple sites however the price maybe different at each site. Therefore I would like my primary key to be a combination of Site Designation and Part Number. How do I define a key which will concatentate the two fields. Your help is appreciated.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Why not use Autonumber as the primary key and have fields for the Site Designation and Part Number?

If you need to later on in a query you can easily concatenate these two fields.

They could also be used to say get the max price for a part across sites, create a list of parts/prices for a site etc
 
Upvote 0
Thought about that but.....

I want to ensure that the same Part Number is not added for the same site, the creation of the composite key would allow me to ensure that I have a distinct value.

Thanks for the thought!
 
Upvote 0
Hi,
have you considered having a dual primary key where both the site and the material are set up in your table as the primary key? This will prevent a material being set up at the same site more than once.
HTH, Andrew. :)
 
Upvote 0
Hi,
open the table in design view, click on "site designation" (I think that is your variable name) so that it is highlighted, hold down the control (Ctrl) key and then click the "part number" so that both fields are now highlighted, release the control key, Click Edit -> Primary Key. Save. Hey presto, you have a dual primary key that won't allow duplicate parts per site.
HTH, Andrew. :)
 
Upvote 0

Forum statistics

Threads
1,221,825
Messages
6,162,165
Members
451,750
Latest member
dofrancis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top