combine two fields as primary key

M

Mas

I have database in which i would like to create the prmary key as being combination of field surname and field date. So that it would look like Smith12/04/04 and could use that as the identifier. Does anyone know if ther is way of doing so?
 
L

Les

There is a way to do it, but are you sure that the
combination of last name and date will give you a unique
key value? Smith is pretty common, and if you try to
enter 2 Smiths with the same date, your primary key will
prevent you.

Anyway, to answer your question. Display table in design
view. Click on your first field, as you normally would to
set the primary key. Then, while holding the shift key
down, click on your second field. Now, both lines should
be highlighted. At this point, if you click on the
primary key symbol, your primary key should be set, using
both fields.
-----Original Message-----
I have database in which i would like to create the
prmary key as being combination of field surname and
field date. So that it would look like Smith12/04/04 and
could use that as the identifier. Does anyone know if ther
is way of doing so?
 
J

Jeff Boyce

Mas

I'm with Les -- your primary key will, by definition, be a unique
identifier. Use of names or even Social Security Numbers is not
particularly sure to be unique.

Have you considered using an Autonumber column?
 
J

John Vinson

using Autonumber will enable to enter the same person more then once, would
it not?

Well, it won't *prevent* it. But you need to use a lot of caution when
using a name as a primary key; names - even combined with birthdates
or other data - are NOT unique.

I'd suggest enforcing all data entry through a Form and using the
Form's BeforeUpdate event (or the name field's) to check the table to
see if another entry with the same name exists, and *warn* the user of
the possible duplication so they can verify whether this is a
duplicate entry or a new person with the same name.
 
J

Jeff Boyce

Define "the same person"...

Are the follow three "persons", all residing at 12345 Elm St, Mytown,
MyState, the "same" person:?
John Smith
John J. Smith
J. J. Smith

If you answered "yes", BRAAAAAA! These three are grandfather, father & son,
and point to some of the difficulty of determining "same person".

I'm with John on this -- there's nothing magical that will prevent a
determined user from entering more than one "Smith" ... and you might not
want to!

JOPO (just one person's opinion)

Jeff Boyce
<Access MVP>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top