Relationship / query problem

P

pkeegs

I have a master client table (Access 2003) which includes a number of
companies. I also have a separate table for shareholders of the companies
using a combobox with data from the master client field. I want to have a
report which provides all the details on the company and a subform showing
the contact details of the shareholders alongside the individual shareholder
names. Every query I have tried only results in the company details being
given to the shareholders. I suspect I have a construction problem somewhere
but can anyone understand what I am trying to do and help me out
 
G

Gina Whipp

pkeegs,

I believe what you have is a missing table...

tblCompany
cCompanyID (PK)
etc...

tblShareholders
sShareholderID (PK)
etc...

MISSING TABLE
tblCompanyShareholders
csCompanyShareholderID (PK)
csCompanyID (FK)
csShareholderID (FK)

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
P

pkeegs

Thanks for the reply Gina - I have two tables, a master client table which
has all their contact details etc. It includes client companies and
individual clients (I don't want to separate them as an individual (read
shareholder) can be a client in their own right). The second table
(shareholders) has a field that looks up individuals in the client table so
they are linked. The queries I have tried so far have included the Client
company from Client Table and its Shareholders from Shareholder table. But
every combination I have tried has always resulted in contact details for the
Client company rather than for the individual shareholder. I realise the
difficulty of trying to adequately explain for you, but there must be a way I
can choose which query field I want the contact details to belong to. Regards
:)
 
G

Gina Whipp

pkeegs,

Please look at tables below and tell me do you have a CompanyID field in the
tblShareholders? If the answer is yes, then you should be able to pull your
data by placing both tables in the query, linking on the ComapnyID field and
pulling the correct information. If no, then please list the fields in the
tables.

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
P

pkeegs

Hi Gina - yes I do have an ID field for each table and my queries have
included the ID. I suspect Ken Sheridan has the answer, but I will have to
spend time with his reply. In an earlier post I said I thought it was a
construction problem and it looks like it. My preference is for Excel but it
was getting cumbersome and I have simply imported the tables I was using
there and tried to build on those. Access is far more powerful than Excel but
takes a lot more getting one's head around - Regards
 
P

pkeegs

Thanks Ken - quite a bit for me to absorb and as I have suggested in a reply
to Gina, my Excel background doesn't quite match what is needed in Access. I
will have to spend some time with your answer to understand what the
implications are for my database. - Regards

KenSheridan via AccessMonster.com said:
It seems to me that the model is a little more complex than might appear at
first sight.

1. Firstly you have a Clients entity type which should be modelled by a
Clients table. This table will have columns which represent the attributes
of clients whether or not the client is a company or an individual, but not
those attributes which are specific to one or the other, e.g. it would not
have a CompanyName columns as this is an attribute only of those clients
which are companies; nor would it have FirstName or LastName columns as these
are attributes only of those clients who are individuals.

2. You have a Companies entity type, but as a company is also a Client the
Companies entity type is a sub-type of clients. Sub-types are modelled by a
one-to-one relationship so you'd have a Companies table related one-to-one to
Clients, i.e. the primary key of Companies is also a foreign key referencing
the primary key of clients. This table would have columns such as
CompanyName representing attributes specific to companies.

3. Individuals who are clients are also a sub-type of clients, and thus
modelled in the same way by an IndividualClients table whose primary key is
also a foreign key referencing the primary key of Clients. However, an
individual is not necessarily a client as they might be a shareholder of a
company but not a client per se, so not all individuals are represented in
this table. Consequently this table would not include columns for attributes
which are common to all individuals, e.g. FirstName, LastName, but only those
attributes which are specific to an individual *as a client*. The common
attributes would be represented by columns in a People table, so the
IndividualClients table would include a foreign key column PersonID
referencing the key of people. IndividualClients is not only a sub-type of
Clients therefore, but also a sub-type of People. A table can only have one
primary key of course so unlike ClientID, PersonID is not both a primary and
foreign key of IndividualClients, but as the relationship with People is
again one-to-one the PersonID column in IndividualClients should be indexed
uniquely.

4. As I said in 3 above you'd have a People table with columns representing
Attributes common all individuals such as FirstName and Lastname. Other
contact details would be represented by columns in this table, though you
might need further realted tables if there can be multiple values of the same
type of attribute, e.g. if a person can have multiple addresses and/or phone
numbers.

5. With the basic model established by these four tables, Clients, Companies,
IndividualClients and People (you can of course use table names of your own
choice, but I'd suggest you use terms which describe the entity type modelled
as closely and as simply as possible) you now have to consider how to model
the shareholdings in companies by people. Gina has already given you the
answer to this; its with a another table which models the many-to-many
relationship between People and Companies, CompanyShareHoldings say. This
will have two foreign key columns such as PersonID and CompanyID referencing
the primary keys of People and Companies respectively. Together these two
columns constitute the composite primary key of the CompanyShareHoldings
table. An important thing to understand is that while this table models a
relationship type, its also an entity type as relationship types are really
just a special kind of entity type. So it can have non-key columns of its
own representing the attributes of each person's shareholding in the company,
such as the number of shares held.


You'll probably find the above easier to understand if you draw it out
diagrammatically as an 'entity relationship diagram', with boxes representing
the entity types and lines representing the relationships between them. The
limitations of a text interface make it difficult to do so as a single
diagram here, so I'll split it in two, the Clients and People table appearing
twice whereas on paper they'd appear only once:

Clients-----Companies----<CompanyShareHoldings>----People

Clients-----IndividualClients-----People

The < and > signs in the above represent the 'many' side of each one-to-many
relationship, the lines without these are on-to-one relationships.

Although you have separated companies and individual clients here, the fact
that each is a sub-type of clients means that you have not really done so in
the way you were perhaps thinking of when you said this is something you
wished not to do. Each is still a client entity; all you've done is model
them in such a way as to eliminate inconsistencies in the data which would be
possible if all were in a single table.

With a structure such as that outlined above, which reflects the underlying
reality rather than imposing an artificial framework on it, you should have
little difficulty in creating queries, forms reports etc.

Ken Sheridan
Stafford, England
Thanks for the reply Gina - I have two tables, a master client table which
has all their contact details etc. It includes client companies and
individual clients (I don't want to separate them as an individual (read
shareholder) can be a client in their own right). The second table
(shareholders) has a field that looks up individuals in the client table so
they are linked. The queries I have tried so far have included the Client
company from Client Table and its Shareholders from Shareholder table. But
every combination I have tried has always resulted in contact details for the
Client company rather than for the individual shareholder. I realise the
difficulty of trying to adequately explain for you, but there must be a way I
can choose which query field I want the contact details to belong to. Regards
:)
[quoted text clipped - 26 lines]

--



.
 
G

Gina Whipp

Just glad you got an answer!

I peeked at your reply to Ken and some links that might be of some help...

Jeff Conrad's resources page:
http://www.accessmvp.com/JConrad/accessjunkie/resources.html

The Access Web resources page:
http://www.mvps.org/access/resources/index.html

A free tutorial written by Crystal (MS Access MVP):
http://allenbrowne.com/casu-22.html

MVP Allen Browne's tutorials:
http://allenbrowne.com/links.html#Tutorials


http://www.databasedev.co.uk/table-of-contents.html

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
P

pkeegs

I have solved my problem by setting the lookup field in the Shareholder table
with extra columns containing the additional data I want to include in the
report and then using a text box with the formula
"=[Shareholders].column(##)' for each additional item. The solution proved
quite simple eventually and I didn't have to reconstruct any tables.

Thanks for all the support from those who replied.
 

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