Building Composit key on the fly, Boy Scout Data Base

D

Dick Patton

Hi all,

I have two tables each is unique. One is the "Merit Badge" tabel the other
"person Id" (name address info) tabel, there is a link tabel "MB-ID_link".
This intent is to connect mert badges with the IDs of Councelors. That works
great, however, i find that i can add duplicate records (same Person, same
Merit badge many times) this is not good.

I created a "check_key" field in the Link tabel which i defined as primary
key. This will stop duplicates from being entered without a lot of code.
The problem is i am not sure how to populate the new key. I know of no way
of concatination in access or where to place the code, but it must be built
before update.

So - I tried: Check_key = trim([MB_code) & [Person_ID]) in the event calle
"before UPdate" that did not work!

It seems like such a simple thig to do!

Help

Dick
 
J

John W. Vinson

Hi all,

I have two tables each is unique. One is the "Merit Badge" tabel the other
"person Id" (name address info) tabel, there is a link tabel "MB-ID_link".
This intent is to connect mert badges with the IDs of Councelors. That works
great, however, i find that i can add duplicate records (same Person, same
Merit badge many times) this is not good.

I created a "check_key" field in the Link tabel which i defined as primary
key. This will stop duplicates from being entered without a lot of code.
The problem is i am not sure how to populate the new key. I know of no way
of concatination in access or where to place the code, but it must be built
before update.

So - I tried: Check_key = trim([MB_code) & [Person_ID]) in the event calle
"before UPdate" that did not work!

It seems like such a simple thig to do!

It is simpler than you're making it, and you certainly do not need to
construct a new field to do it.

Instead, open the link table in design view. ctrl-click the Person ID and the
Merit Bage fields so they're both selected (darkened). Click the key icon to
make these two fields a joint, two-field Primary Key; this will require that
every record be unique for the combination, even though each field by itself
can have duplicates.

If you already have a primary key, you can instead use the Indexes tool on the
toolbar to create a unique twofield index. Put some distinctive index name in
the left column, and the person ID next to it; put the MB Code in the second
column just below the person ID, and check the "unique" checkbox.
 
J

Jeff Boyce

Dick

I'm not sure I understand your situation, what it is that you are trying to
use Access to do.

One possible scenario for what you've described might be:

* You have people
* You have merit badges
* You have people-with-meritbadge(s)

If that's your situation, I think you need to be looking at three tables
instead of two.

More information, please...

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
S

Steve

When entering data into a database, you have to rely on the data entry
person at some point!

You need these tables:
TblPerson
PersonID
<person fields>

TblMeritBadge
MeritBadgeID
MeritBadgeName

TblMeritBadgeAward
MeritBadgeAwardID
PersonID
MeritBadgeID
DateMeritBadgeAwarded

You need a form/subform for entering data. Base the main form on TblPerson.
Base the subform on TblMeritBadgeAward. Set the LinkMaster and LinkChild
properties to PersonID. Use a combobox in the subform to enter MeritBadgeID.
Your form/subform will display a single person and a list of merit badges
awarded to that person. You can sort the merit badges in alphabetical order.
Now all you need do is rely on the data entery person not to enter a
duplicate merit badge for any person.

Steve
(e-mail address removed)
 
J

John... Visio MVP

Steve said:
You need a form/subform for entering data. Base the main form on
TblPerson. Base the subform on TblMeritBadgeAward. Set the LinkMaster and
LinkChild properties to PersonID. Use a combobox in the subform to enter
MeritBadgeID. Your form/subform will display a single person and a list of
merit badges awarded to that person. You can sort the merit badges in
alphabetical order. Now all you need do is rely on the data entery person
not to enter a duplicate merit badge for any person.

Steve


You forgot the part about chastising the poster for his table design and
that only you can help him --- for a fee.

John...
 
J

John W. Vinson

Now all you need do is rely on the data entery person not to enter a
duplicate merit badge for any person.

Or you can use Access as it is designed... with a unique index on the two
fields. You're not enhancing your reputation any, Steve.
 
D

Dick Patton

John,

Yes, Yes, that worked perfectly. It was simpler than i thought.

Rule: Use the DBMS to do the work when ever you can!

Thank loads....

John W. Vinson said:
Hi all,

I have two tables each is unique. One is the "Merit Badge" tabel the other
"person Id" (name address info) tabel, there is a link tabel "MB-ID_link".
This intent is to connect mert badges with the IDs of Councelors. That works
great, however, i find that i can add duplicate records (same Person, same
Merit badge many times) this is not good.

I created a "check_key" field in the Link tabel which i defined as primary
key. This will stop duplicates from being entered without a lot of code.
The problem is i am not sure how to populate the new key. I know of no way
of concatination in access or where to place the code, but it must be built
before update.

So - I tried: Check_key = trim([MB_code) & [Person_ID]) in the event calle
"before UPdate" that did not work!

It seems like such a simple thig to do!

It is simpler than you're making it, and you certainly do not need to
construct a new field to do it.

Instead, open the link table in design view. ctrl-click the Person ID and the
Merit Bage fields so they're both selected (darkened). Click the key icon to
make these two fields a joint, two-field Primary Key; this will require that
every record be unique for the combination, even though each field by itself
can have duplicates.

If you already have a primary key, you can instead use the Indexes tool on the
toolbar to create a unique twofield index. Put some distinctive index name in
the left column, and the person ID next to it; put the MB Code in the second
column just below the person ID, and check the "unique" checkbox.
 
D

Dick Patton

Thank you, Jeff i am sorry i did not communicate well. There are 3 table and
MB-Link forms the retionship between the merit badge and the councilor but
both are one to many relationships so i neede3d a way to store only those
that are unique combinations and John's suggestion worked perfectly. I just
wish i could trap the error and give a used friendly message like "this
record already exists".

Jeff Boyce said:
Dick

I'm not sure I understand your situation, what it is that you are trying to
use Access to do.

One possible scenario for what you've described might be:

* You have people
* You have merit badges
* You have people-with-meritbadge(s)

If that's your situation, I think you need to be looking at three tables
instead of two.

More information, please...

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

Dick Patton said:
Hi all,

I have two tables each is unique. One is the "Merit Badge" tabel the
other
"person Id" (name address info) tabel, there is a link tabel "MB-ID_link".
This intent is to connect mert badges with the IDs of Councelors. That
works
great, however, i find that i can add duplicate records (same Person, same
Merit badge many times) this is not good.

I created a "check_key" field in the Link tabel which i defined as primary
key. This will stop duplicates from being entered without a lot of code.
The problem is i am not sure how to populate the new key. I know of no
way
of concatination in access or where to place the code, but it must be
built
before update.

So - I tried: Check_key = trim([MB_code) & [Person_ID]) in the event
calle
"before UPdate" that did not work!

It seems like such a simple thig to do!

Help

Dick


.
 
J

J_Goddard via AccessMonster.com

Sorry Stevie - WRONG answer!!!

One of the things we try to do as developers is to anticipate users' mistakes
and prevent or correct them. In this case, detecting a duplicate entry of a
merit badge is a trivial task - any any decent developer would include it,
and not "rely on the data entery person not to enter a duplicate merit
badge for any person."


Small wonder you have to grovel here for work, if that's the type of advice
you give.


When entering data into a database, you have to rely on the data entry
person at some point!

You need these tables:
TblPerson
PersonID
<person fields>

TblMeritBadge
MeritBadgeID
MeritBadgeName

TblMeritBadgeAward
MeritBadgeAwardID
PersonID
MeritBadgeID
DateMeritBadgeAwarded

You need a form/subform for entering data. Base the main form on TblPerson.
Base the subform on TblMeritBadgeAward. Set the LinkMaster and LinkChild
properties to PersonID. Use a combobox in the subform to enter MeritBadgeID.
Your form/subform will display a single person and a list of merit badges
awarded to that person. You can sort the merit badges in alphabetical order.
Now all you need do is rely on the data entery person not to enter a
duplicate merit badge for any person.

Steve
(e-mail address removed)
[quoted text clipped - 23 lines]
 

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