Combo box and link between tables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an Education degree table that includes five records for now: Diploma,
Associate Degree, BS, MS and Doctorate. For each employee, I will need to
choose and write the highest degree she/he earned from the combo box that is
bounded to this EducationDegree table. For employees that have earned BS, or
MS or Doctorate degree, I need to write specificaly in which area they earned
BS, MS or Doctorate. How do I capture this additional information from the
combo box? Do I need to update my table first everytime I see a new BS degree
and then go the form that contains this combo box to choose?

How do I link the Education Degree table to my Employee table that has
EmployeeID as primary key for future reports?

Can anyone help me out here?
 
The degrees and the areas of expertise in which they are awarded are
different entity types, so should be represented by separate tables, call
them Degrees and SubjectAreas say. There is a many-to-many relationship
between them as each degree level can be in many subject areas, and each
subject area can be that for more than one degree level. The relationship
should be modelled by a third table with two foreign key columns DegreeID and
SubjectAreaID referencing the primary keys of Degrees and SubjectAreas. Lets
call this third table DegeeSubjectAreas say. You could use these two columns
in combination as the primary key of DegeeSubjectAreas, but in your Employees
table you'd then need to reference it by two columns, so it will be easier to
give it a separate numeric DegeeSubjectAreaID primary key column, which can
be an autonumber.

For each subject area in which a degree is awarded there will be a row in
DegeeSubjectAreas, so if PhDs are awarded in five subject areas and diplomas
in 10 there would be 5 rows with the ID for Diploma in the DegreeID column
and the relevant 5 IDs for the subject areas in the SubjectAreaID column; for
PhDs there would be 10 rows with the ID for Diploma in the DegreeID column
and the relevant 10 IDs for the subject areas in the SubjectAreaID column.

To insert rows into the DegeeSubjectAreas table you could have a subform
based on the table in a parent form based on the Degrees table. The subform
and parent form would be linked on the DegreeID columns. The subform would
have a combo box bound to the SubjectAreaID column and listing all the
subject areas from the SubjectAreas table, so you simply have to select from
the list when adding rows in the subform.


In the Employees table you would have a foreign key DegeeSubjectAreaID
column and in the form based on this table a combo box bound to this with a
RowSource property of:

SELECT DegeeSubjectAreaID, Degree, SubjectArea
FROM Degrees, DegreeSubjectAreas, SubjectAreas
WHERE Degree.DegreeID = DegreeSubjectAreas.DegreeID
AND DegeeSubjectAreas.SubjectAreaID = SubjectAreas.SubjectAreaID
ORDER BY Degree, SubjectArea;

Set the BoundColumn property of the combo box to 1, its ColumnCount property
to 3, its ColumnWidths property to 0cm;3cm;3cm (or rough equivalent in
inches. Experiment to get the best fit but the first dimension must be
zero), and the ListWidth property to 6cm (i.e. the sum of the ColumnWidths).

The list will show all degrees with their subject areas, so its simply a
question of selecting one from the list. When a selection is made only the
degree will show in the control, so put an unbound text box on the form with
a ControlSource property of:

=cboDegeeSubjectAreaID.Column(2)

where cboDegeeSubjectAreaID is the name of the combo box. The column
property is zero-based so Column(2) is the third column. The text box will
therefore show the subject area selected.

To add new degrees and/or subject areas you insert rows into the relevant
table(s) and then into the DegeeSubjectAreas table as necessary. If the
degree and subject area are already in their tables then its just a case of
adding a row to the latter table if you encounter an employee for the first
time with that degree in that subject area.

For reporting you simply need to join the Employees table to the other
tables, e.g.

SELECT Employee, <more columns form Employees table>,
Degree, SubjectArea
FROM Employees, Degrees, DegreeSubjectAreas, SubjectAreas
WHERE Degree.DegreeID = DegreeSubjectAreas.DegreeID
AND DegeeSubjectAreas.SubjectAreaID = SubjectAreas.SubjectAreaID
AND Employees.DegeeSubjectAreaID = DegeeSubjectAreas. DegeeSubjectAreaID;

Ken Sheridan
Stafford, England
 
Ken,

Oh, my. Thanks so much for your time in trying to help me here!!! I really
appreciate your detail directions of solving this problem I have. I am
still learning ACCESS. I don't quite understand some points you make in your
message. Do you mind providing further explainations on this first questions
I have after reading it?

My Question for insert rows into relevant tables: Is my understaning correct
that the parent form is basded on Degree table, the subform based on
SubjectArea table? How do I adding rows (subject areas) in the subform? Do
you mean I need to update three tables: The Degree table, the SubjectArea
table, and DegreeSubjectArea table first everytime when I encounter an
employee for the first time withat that degree in that subject area, so that
I can choose from the combo box that bounds to the subjectarea table?

Thanks so much in advance!

Ally


The degrees and the areas of expertise in which they are awarded are
different entity types, so should be represented by separate tables, call
them Degrees and SubjectAreas say. There is a many-to-many relationship
between them as each degree level can be in many subject areas, and each
subject area can be that for more than one degree level. The relationship
should be modelled by a third table with two foreign key columns DegreeID and
SubjectAreaID referencing the primary keys of Degrees and SubjectAreas. Lets
call this third table DegeeSubjectAreas say. You could use these two columns
in combination as the primary key of DegeeSubjectAreas, but in your Employees
table you'd then need to reference it by two columns, so it will be easier to
give it a separate numeric DegeeSubjectAreaID primary key column, which can
be an autonumber.

For each subject area in which a degree is awarded there will be a row in
DegeeSubjectAreas, so if PhDs are awarded in five subject areas and diplomas
in 10 there would be 5 rows with the ID for Diploma in the DegreeID column
and the relevant 5 IDs for the subject areas in the SubjectAreaID column; for
PhDs there would be 10 rows with the ID for Diploma in the DegreeID column
and the relevant 10 IDs for the subject areas in the SubjectAreaID column.

To insert rows into the DegeeSubjectAreas table you could have a subform
based on the table in a parent form based on the Degrees table. The subform
and parent form would be linked on the DegreeID columns. The subform would
have a combo box bound to the SubjectAreaID column and listing all the
subject areas from the SubjectAreas table, so you simply have to select from
the list when adding rows in the subform.
(My Question: Is my understaning correct that the parent form is basded on
Degree table, the subform based on SubjectArea table? How do I adding rows
(subject areas) in the subform? Do you mean I need to update three tables:
The Degree table, the SubjectArea table, and DegreeSubjectArea table first
everytime when I encounter an employee for the first time withat that degree
in that subject area, so that I can choose from the combo box that bounds to
the subjectarea table?
 
Ally:

The number of tables you have to update depends on what rows are in them
already. The only time you'd have to update all of them would be if you
encountered a new employee who has a degree of a type which you'd not
encountered before in a subject area which you'd not encountered before. Say
you encounter an employee with a PhD in Molecular Biology. If you don't
already have row for PhD (or Doctorate if you are not differentiating between
PhD, D Phil, MD etc) in the Degrees table an you don't have a row in the
SubjectAreas table for Molecular Biology, you would first have to add a row
in each of these tables, then a row in the DegreeSubjectAreas table with
values in its DegreeID and SubjectAreaID columns which reference the two rows
you've just added to the Degrees and SubjectAreas tables. (Incidentally
you'll notice that I've used plural nouns for the table names; the usual
convention in relational database design is to use plural or collective nouns
for table names and singular nouns for column names. Some developers also
use proper case for table names and lower case for column names, but I tend
to use the former for both, or more strictly speaking CamelCase where the
individual parts are tacked together without a space and capitalized; others
prefer camelCase where the initial letter is lower case. Don't use all upper
case, though, as this conflicts with the convention that SQL keywords are
written in upper case)

In the above situation you'd have to insert rows into the 3 tables before
you can put the DegreeSubjectAreaID value in the Employees table. If you'd
previously encountered someone with a PhD but no-one with any form of degree
in Molecular Biology then you'd just insert rows into the SubjectAreas and
DegreeSubjectAreas tables before putting the DegreeSubjectAreaID value in the
Employees table as you'd already have a row in Degrees for PhD.

Normally with this sort of data you'd try and insert as many rows as you can
think of into the Degrees, SubjectAreas, and Degree SubjectAreas tables at
the outset so that you only have to insert new rows into those tables when
unusual degrees or subject areas are encountered, in most cases you'd simply
select a Degree/Subject Area combination from the combo box when adding or
updating an employee's qualification data.

As far as forms are concerned you'd obviously have an Employees form, and in
it the combo box bound to the DegreeSubjectAreaID column (field) in the
Employees table.

You are correct that the other form would be based on the Degrees table (or
better still a sorted query on that table so that the form's records are
ordered). The subform in this form would be based on the DegreeSubjectAreas
table (or again a sorted query). The subform and parent form are linked by
setting the subform control's LinkMasterFields and LinkChildFields properties
to DegreeID. When you want to associate a subject area with the parent
form's current degree record you simply add a row in the subform. The
subform would be in continuous form view and have a single control, a combo
box bound to the SubjectAreaID column. The RowSource property for this combo
box is quite simple as it just looks up the subject areas from the
SubjectAreas table:

SELECT SubjectAreaID, SubjectArea
FROM SubjectAreas
ORDER BY SubjectArea;

Like the combo box on the Employees form you hide the first column by
setting the combo box's BoundColumn property to 1, its ColumnCount to 2 and
its ColumnWidths to 0cm;8cm or rough equivalent in inches. This time as the
combo box only has one visible column you can leave the ColumnWidths property
set at Auto.

You'd also have a form based on the SubjectAreas table (or again a sorted
query would be better) for adding new subject areas, or editing existing ones.

There are other refinements you can include in your forms such as adding a
new degree/subject area in the Employees form if the one you want is not
already in the list. This involves opening the Degree form so that you can a
degree record, or select an existing one and add a new subject area to it.
In the latter case you can do this directly in the combo box on the subform
by typing in the new subject area; this requires a little bit of code to be
written, however, so I'd leave that until later when everything else is
working satisfactorily.

I hope the above is not too confusing. It probably sounds complicated, but
is actually pretty straightforward to implement once you get used to working
with forms and tables.

One thing you might like to consider is whether there would be any advantage
in your recording not just the highest degree awarded to each employee, but
all degrees they have been awarded. This would simply require the addition
of another table to model the many-to-many relationship between Employees and
DegreeSubjectAreas, and instead of a combo box in the Employees form you'd
have an academic qualifications subform based on this new table. The new
table would have 3 columns, EmployeeID, DegreeSubjectAreaID and DateAwarded.
For a modest extension of the database you might gain a significant increase
in useful data regarding employees. One reason I ask this is that I have a
first degree (BA) and a post-graduate diploma. I'm not really sure which I'd
class as the 'higher' qualification. The latter presumes the existence of
the former, so I guess would be 'higher' but if only the diploma were
recorded it would give a very limited picture of my academic qualifications
and areas of expertise. Also, some people have degrees of the same level in
different subjects, so which do you then record if only one qualification can
be entered?

Don't hesitate to post back if you need more help with this.

Ken Sheridan
Stafford, England
 
Ken,

Thanks again for your continuous help! I feel I am so lucky to have you
answer my questions! Each of your replies is not only helpful but also teachs
me quite a lot about ACCESS expecially those details designs/trick you
mentioned in your reply. I really appreciate it!!!

I have some questions related to your message.

1. I think I am a little confused about the way of updating tables (adding
non-existing degree in Degrees table, non-existing SubjectArea in
SubjectAreas table, and corresponding row in the DegreeSubjectAreas table).
Yes, I am going to insert as many rows as I can think of into the Degrees,
SubjectAreas, and DegreeSubject Areas tables at the outset so that people who
later help me enter the data we collects from more than 200 employees will be
able to select a Degree/SubjectArea combination from the combo box in the
Employee form (including EmployeeName, Educations, Position, Certifications,
ProfessionalOrgnizations, etc. ) when adding/updating an employee's
information. However, it would be pretty hard for people who are iliterate
with any database or any computer softwares to switch from Access application
(Employee from) to Access Object screen to find correct tables(tblDegrees,
tblSubjectAreas and tblDegreeSubjectAreas) and update each or part of these
three tables based on different situation whenever she/he encounters a new
degree, or new subject or new both that an employee has. Because if these
tables are not correctly updated, you would not be able to find the right
combination to choose from out of the combo box in the Employee form. The
more difficult task for data entry people is to how and when to update which
tables at any given situation when they cannnot find any right combination
from the Employee form. I am not sure whether this is what you suggest to do?
I may misunderstand of what you mean...or do you mean the No. 2 below? Please
get back to me...?

2. You mentioned in your first reply that "To insert rows into the
DegreeSubjectAreas table you could h ave a subform based on the table
(DegreeSubjectAreas) in a parent form based on the Degrees table... The
subform would have a combo box bound to the SubjectAreaID column and listing
all the subject areas fromt he SubjectAreas table, so you simply have to
select from the list when adding rows in the subform. " I am not sure if this
is what you suggest for data entry people to do in the Access application to
adding rows. If so, for data entry people, how do I let them adding rows in
this subform when the combination is not listed? Do they need to switch from
the parent from based on Degree table to Access Objects, choose Tables under
the Objects and update each or part of the three tabels (tblDegrees,
tblSubjectAreas, tblDegreeSubjectAreas) mentioned in No. 1 above? If not, do
I need to set up a Command Button in the application for people who are using
it to updating/editing/adding new Degrees/SujbectAreas/DegreeSubjectAreas?

3. In your second reply, you mentioned in your second reply that "There are
other refinements you can include in your forms such as adding a new
degree/subject area in the Employees form if the one you want is not already
in the list. This involves opening the Degree form so that you can a degree
record, or select an existing one and add a new subject area to it. In the
latter case you can do this directly in the combo box on the subform by
typing in the new subject area; this requires a little bit of code to be
written, however, so I'd leave that until later when everything else is
working satisfactorily." Sound like this is really what I was thinking about
initially, but requiring writing codes which I don't know how. So If I cannot
adding/updating a new subject area directly from Employee form as you
mentioned, what is another way (or easier way) to do it? I know you also
mentioned that "You'd also have a form based on the SubjectAreas table (or
again a sorted query would be better) for adding new subject areas or editing
existing one." How do I switch from the Employee form when I am not seeing
the Degree and SubjectArea combination listed from the combo box
cboDegreeSubjectAreaID to add new Degree in table Degrees, add new
SubjectArea in table SubjectAreas and add Degree/SubjectAreas combination in
DegreeSubjectAreas table? Do I need to set up a three command button like
Update Degree, Update SubjectAreas, Update Degree/SubjectArea somewhere in
the mainmenu of the application? But it seems very bulky and silly, Could you
please provide more explanations on this?

4. As matter of fact, your promotion of thinking about recording all degrees
that applied is my reality I need to face because I just found that some
people have earned more than one master degree for examle MBA & MHA, or MHA &
MRM, sometimes, MBA and Ph D in Physics. I understand there is a need to set
up the many-to-many relationship betwen employees and DegreeSubjectAreas. How
do I record both Master Degrees and count the highest degree as the MS, for
the latter case, record MBA and PHD in Physics and count the hightest degree
as the PH D since I need cound the number of peple in each type for highest
degree. Do I still need to the combox cboDegreeSubjectAreadID in my Employee
form? I don't think I understand you saying haveing an academic
qualifications subform (based on new table) instead in the Employee form.
Would you please elaberate a little more? Also I don't know what's the
purpose to keep the DateAwarded in the new table. Highest degree doesn't
necessarily mean the latest degree a person earns, right? because she/he can
earn anther MS degree say MBA after she/he has earned a PHD in Physics.

5. How do you set up a foreign key in a table?

Oh, my gosh! I have written so many questions to you! and I bet it will take
you a quite some time to just write me back not to mention the technich
involved in. But please please get back to me and I own you a million!

Ally
 
Ally:

I'm glad you've found my replies useful, and thank you for your kind words.
This thread is just the sort of thing on which I like to spend more time than
I would normally because you clearly want to do things the correct way. So
many of the questions I see are from people who have devised some bizarre way
of doing something and just want to know how to implement it regardless of
how bad a technique it is, and are not interested in being steered in the
right direction.

Coincidentally, what you are trying to achieve is very similar to something
I had from a member of a forum in which I used to participate. It was one of
the first posts I answered there and the guy in question was then new to
Access; in fact I hadn't been using it very long myself, but I did have prior
experience with other database management systems. He soon became very
proficient and started replying regularly to other members posts. So in a
little while I'm sure you'll be equally proficient.

I'll come back to your specific questions later but I think the best way I
can show you how this sort of application is put together would be to put
together a little demo file with the tables we've discussed and some forms
and a report to illustrate how data can be entered or edited in the forms,
and presented in a report. This is something I can do very quickly. The
tables will be simplified in terms of the columns they contain compared with
a real life situation, but the essential structure will be there and it would
be just a case of adding columns to the tables and controls to the forms to
expand it.

Until recently I could post a file in my old forum, where I was a staff
member, and could have given you a link to it, but having now left the forum
due to the decline in its activity I'm no longer able to do so. If you'd
care to email me at the following (munged) address, however, I could mail you
the file once I've thrown it together:

ken<dot>sheridan<at>dsl<dot>pipex<dot>com

It won't have all the finesse of a fully developed application of course, so
the forms or report won't be visually as good as I'd produce in a proper
application, but apart from its aesthetic inadequacies it should serve to
illustrate what I've said so far and what I'll say later when I reply to your
detailed questions.

I normally distribute demo files in Access 2000 format as most people have
that version or later. If you need it in Access 97, however, let me know.
If you would rather not email me directly and disclose your email address
please say so; I would understand completely.

Ken Sheridan
Stafford, England
 
Ally:

As promised I'm addressing your detailed questions below:
1. I think I am a little confused about the way of updating tables (adding
non-existing degree in Degrees table, non-existing SubjectArea in
SubjectAreas table, and corresponding row in the DegreeSubjectAreas table).
Yes, I am going to insert as many rows as I can think of into the Degrees,
SubjectAreas, and DegreeSubject Areas tables at the outset so that people who
later help me enter the data we collects from more than 200 employees will be
able to select a Degree/SubjectArea combination from the combo box in the
Employee form (including EmployeeName, Educations, Position, Certifications,
ProfessionalOrgnizations, etc. ) when adding/updating an employee's
information. However, it would be pretty hard for people who are iliterate
with any database or any computer softwares to switch from Access application
(Employee from) to Access Object screen to find correct tables(tblDegrees,
tblSubjectAreas and tblDegreeSubjectAreas) and update each or part of these
three tables based on different situation whenever she/he encounters a new
degree, or new subject or new both that an employee has. Because if these
tables are not correctly updated, you would not be able to find the right
combination to choose from out of the combo box in the Employee form. The
more difficult task for data entry people is to how and when to update which
tables at any given situation when they cannnot find any right combination
from the Employee form. I am not sure whether this is what you suggest to do?
I may misunderstand of what you mean...or do you mean the No. 2 below? Please
get back to me...?

So far we've mainly talked about the logical model, i.e. the tables which
represent the real world entities and how they relate to each other. That's
the key to a successful database, but the users need to interface with that
model in such a way that all the technicalities are hidden. That's where the
other part of good database development comes into play, designing an
interface, of which forms are the principle tool, so that the user can
undertake the necessary tasks of updating and querying the database
painlessly. So when a user comes across a degree/subject area combination
which is not already represented in the database they can add it by following
a simple and intuitive sequence of events. This will involve inserting new
rows into at least one table, at most three, but whichever is the case the
user will be able to do what is necessary without needing to know what is
happening under the hood. They simply interact with controls on forms.
2. You mentioned in your first reply that "To insert rows into the
DegreeSubjectAreas table you could h ave a subform based on the table
(DegreeSubjectAreas) in a parent form based on the Degrees table... The
subform would have a combo box bound to the SubjectAreaID column and listing
all the subject areas fromt he SubjectAreas table, so you simply have to
select from the list when adding rows in the subform. " I am not sure if this
is what you suggest for data entry people to do in the Access application to
adding rows. If so, for data entry people, how do I let them adding rows in
this subform when the combination is not listed? Do they need to switch from
the parent from based on Degree table to Access Objects, choose Tables under
the Objects and update each or part of the three tabels (tblDegrees,
tblSubjectAreas, tblDegreeSubjectAreas) mentioned in No. 1 above? If not, do
I need to set up a Command Button in the application for people who are using
it to updating/editing/adding new Degrees/SujbectAreas/DegreeSubjectAreas?

No, they don't go anywhere the database window; in fact it can be hidden
completely. As I said above, its all dine via controls on forms in a way
that makes it an intuitive process for the user. In your case I think a
button in the subform would be the best solution, though it can also be done
via an event of the combo box on the subform; the DblClick event is used
commonly to add new items not in a combo box's list in situations where it
can't be dome simply by typing in the new item, as in you case where the item
is a combination of two values, the degree and the subject area. What I
often do is put a small button beside the combo box and give it a 'tool tip'
so that when the mouse pointer is over it a little message appears saying
'Click to add new degree/subject area'.
3. In your second reply, you mentioned in your second reply that "There are
other refinements you can include in your forms such as adding a new
degree/subject area in the Employees form if the one you want is not already
in the list. This involves opening the Degree form so that you can a degree
record, or select an existing one and add a new subject area to it. In the
latter case you can do this directly in the combo box on the subform by
typing in the new subject area; this requires a little bit of code to be
written, however, so I'd leave that until later when everything else is
working satisfactorily." Sound like this is really what I was thinking about
initially, but requiring writing codes which I don't know how. So If I cannot
adding/updating a new subject area directly from Employee form as you
mentioned, what is another way (or easier way) to do it? I know you also
mentioned that "You'd also have a form based on the SubjectAreas table (or
again a sorted query would be better) for adding new subject areas or editing
existing one." How do I switch from the Employee form when I am not seeing
the Degree and SubjectArea combination listed from the combo box
cboDegreeSubjectAreaID to add new Degree in table Degrees, add new
SubjectArea in table SubjectAreas and add Degree/SubjectAreas combination in
DegreeSubjectAreas table? Do I need to set up a three command button like
Update Degree, Update SubjectAreas, Update Degree/SubjectArea somewhere in
the mainmenu of the application? But it seems very bulky and silly, Could you
please provide more explanations on this?

No, you'd just have the one button as described in my answer to 2 above.
The form this takes you to would then allow the user to select or add a new
degree and or subject area as necessary. In this case as both are just
single column items adding a new degree or subject area is simply a case of
typing it into the relevant combo box.
4. As matter of fact, your promotion of thinking about recording all degrees
that applied is my reality I need to face because I just found that some
people have earned more than one master degree for examle MBA & MHA, or MHA &
MRM, sometimes, MBA and Ph D in Physics. I understand there is a need to set
up the many-to-many relationship betwen employees and DegreeSubjectAreas. How
do I record both Master Degrees and count the highest degree as the MS, for
the latter case, record MBA and PHD in Physics and count the hightest degree
as the PH D since I need cound the number of peple in each type for highest
degree. Do I still need to the combox cboDegreeSubjectAreadID in my Employee
form? I don't think I understand you saying haveing an academic
qualifications subform (based on new table) instead in the Employee form.
Would you please elaberate a little more? Also I don't know what's the
purpose to keep the DateAwarded in the new table. Highest degree doesn't
necessarily mean the latest degree a person earns, right? because she/he can
earn anther MS degree say MBA after she/he has earned a PHD in Physics.

The concept of 'highest degree' is not something inherent in the data, e.g.
its not necessarily the last awarded degree as you say, so it cannot be
computed from the degree data for an employee. Rather it’s a matter of
choice for the user based on a 'business rule'. This means it has to be
indicated by another column (field) in the table which models the
many-to-many relationship between Employees and DegreeSubjectAreas; lets call
this table EmployeeAcademicQualifications. This could be a Boolean (Yes/No)
column and in the subform would be the ControlSource of a check box. Some
validation code would need to be written so that a user can only set one
'Principal Qualification' per employee, prompting the user to say whether
they want any existing 'Principal Qualification' to be replaced by the new
one. This is easily done with some code in the combo box's BeforeUpdate
event procedure.
5. How do you set up a foreign key in a table?

A foreign key is simply a column in one table (the referencing table) which
references the primary key column of another table (The referenced table); it
can also be multiple columns in some situations. Often a primary key is an
autonumber, but the corresponding foreign key in a referencing must not be an
autonumber but a straightforward long integer number data type. This is
because foreign key values are not unique, e.g. you might have a CustomerID
autonumber primary key of a customers table and a long integer CustomerID in
an Orders table; there might be several orders per customer so their
CustomerID would be repeated in several rows of Orders. You don't define a
foreign key in the table design, but by setting up a relationship between the
tables via the Relationship Window. When you do so you can, and usually
will, enforce referential integrity. This means you can't insert a row into
the referencing table until a matching row exists in the referenced table,
e.g. you can't insert an Orders row for a customer who does not yet exist in
Customers. You can also enforce 'cascade updates' which means that if you
change a primary key value all the foreign key values which reference it in
other tables are automatically changed. If the primary key is an autonumber
this is not necessary as an autonumber value can't be changed. Also you can
enforce 'cascade deletions'; this means if you delete a row from a referenced
table all rows in the other table which reference that row will automatically
deleted. You need to think carefully before doing this; in many cases you
will simply want to enforce referential integrity as this means that a row in
a referenced table cannot be deleted if a matching row exists in a
referencing table, e.g. I would not be able to delete the row for San
Francisco in a Cities table if I had customers in San Francisco in a
Customers table (which I do have, as it happens). If I had no san Francisco
customers, however, I'd be able to delete the row for that city from the
Cities table. Enforcing cascade deletions would not be appropriate here but
might be in the case of the relationship between Customers and Orders, as if
I choose to delete a customer from the database I would almost certainly want
to delete their order records too, as they would be meaningless without a
customer to go with them.

You should find that all I've said above is implemented in the demo file
I'll send you. It sounds complex and like a lot of work when written out,
but its actually very straightforward to do, so I'm sure it will be a lot
clearer when you see the demo database. I'll include an explanation specific
to what I do in the demo in my email when I send it to you.

Ken Sheridan
Stafford, England
 
Ken,

Thanks so much for checking my post here! As you can see, how novice I am
about the Access! Your explanations about Foreign key is so clear and
complete, which I really appreicate it!

Can't wait to see the demo file you are sending to me so that I can connect
what you said/suggest in the message with the demo database... But before
that, can I ask you another question related to the multiple degrees for an
employee?

I guess I didnot make my question clear in previous message. I mean to say
that we want to record all the degrees that an employee has earned in the
database but only count 1 for the highest degree. For example, if a person
has both MBA & MHA, even though we record both degrees in database, we would
only count him/her once for the Master Degree as we need count number of
employees for highest level of education (such as # of people who have
highest education of diploma, # of people who have highest education of BS, #
of peoople who have highest education of MS, and # of people who have highest
education of PHD) and the highest level of education for this person is
Master Degree no matter how many MS degrees he/she has earned. If a person
has MS of Nursing and also PHD in Psych, we could only count him/her in the
number of PHD and ignore the MS of nursing degree he/she earned since we only
consider the highest degree. I am not sure whether the table
EmployeeAcademicQualifications you mentioned would work in this case because
I don't really know how to keep all records of degree for a person but only
count the highest degrees for reporting purpose. Do I need to set upt a value
for each degree (Diploma, Associate Degree, BS, MS, PHD) somewhere in the
database for 1 to 5 with 5 as the highest level so that a person has degree
of 4 and 5 will be only counted into 5 (PHD) category?

You probably would feel that my quetions never end, ha? Sorry for keep
bugging you. But it seems that I don't know any person who knows well about
ACCESS like you do.

Thanks a bunch!

Ally
 
Ally:

Even though you record all qualifications, when using the data you can
exclude all the qualifications but the one designated as 'highest' by means
of a criterion in a query. When working with data you actually rarely work
with the tables themselves (base tables as they are called to differentiate
them from the result tables of a query, which only exist as a virtual tables
in memory, not real tables stored on disk). In query design view you simple
put True in the criteria row of the PrincipalQualification column. In SQL
the query's WHERE clause would be:

WHERE PrincipalQualification = TRUE

or simply:

WHERE PrincipalQualification

Ken Sheridan
Stafford, England
 
Back
Top