Primary Key Help Please

V

Vuunderboy

I am trying to find out if there is any way I can set up a table with a
primary key defined by me, in the following manner: The pKey would be the
primary key, but it would be constructed by concatenating the values from
dat001 and dat002 below:

TABLE EXAMPLE:
pKey dat001 dat002
===== ====== ======
zipbaba zip baba
heshe he she

This way, if a user added dat001 as boo and dat002 as ger, the primary key
constructed would be "booger". I could then index this, so if a user tries
to add a value already in the table, it would kick them.

Any ideas? I really appreciate any help at all on this matter.

-Scott-
 
A

Albert D. Kallal

You just have to go to the table in design mode. Hold down the ctrl-key, and
then click on field dat001, and then click on dat002.

BOTH fields will be highlighted. Now, simply click on the primary key
value,a and you are done...
 
A

Allen Browne

Yes, you can create a primary key field, and use the AfterUpdate event
procedure of both dat001 and dat002 to generate the p.k. value if the form
is at a new record, and handle the possibiltiy of duplicates with some code.

If the goal is to keep the combination, unique, you don't need the pKey
field at all. In table design view, select both dat001 and dat002 together,
and press the Key icon on the toolbar. You now have a primary key made up to
two the fields, so they will be unique.

If you are allergic to having a 2-field p.k. because it would make
relationships with other tables more difficult, you could achieve the same
result by making a 2-field index that is unique and required, as well as an
AutoNumber p.k.
 

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