By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

Relationships in Access

P: 67
I have a Contractors table and an Employees table, and I would like to link them both to my Trades table, so that any given trade can have a list of both Employees and Contractors who have that trade assigned.

Is it possible to link the same field to two different tables? Or how might I get this functionality?

Thanks!

CB55
Feb 19 '08 #1
Share this Question
Share on Google+
4 Replies


Expert Mod 2.5K+
P: 2,545
I have a Contractors table and an Employees table, and I would like to link them both to my Trades table, so that any given trade can have a list of both Employees and Contractors who have that trade assigned.

Is it possible to link the same field to two different tables? Or how might I get this functionality?

Thanks!

CB55
Hi CB55. Certainly possible to link the Contractors and the Employees to Trades, though not in one table. The relationship between trades and contractors, and trades and employees, is many-to-many. Each contractor can have more than one trade (plumbing, electrical, joinery say), and each trade is a feature of more than one contractor. Many-to-many's are resolved into two one-to-many relationships using an intermediate table - a linking table - which contains the key fields of both joined tables (contractor and trades, or employees and trades). The link table is joined to contractor so that there is a one-to-many between contractor and ContractorTrades, and ContractorTrades is joined to Trades as a many-to-one.

There is a good article about normalisation and table relationships in the forum, at Database Normalization and Table structures

I don't know what the key fields of your tables are, but producing linking tables is quite straightforward. Once done, you need to be able to add the data to them - and for end-users this can be done using a form-subform structure (adapting the contractor main form to include a trades subform, for instance).

-Stewart
Feb 19 '08 #2

P: 67
Hi Stewart,

Thanks for your response. I should probably clarify my goal to make sure that I'm following the right instructions. I have a Tasks table as well as a Tasks form. The Tasks form will be used to add new tasks and indicate the trades required to complete the tasks. I have a TradeID combobox controlled from the Trades table, and I'd like to be able to select a trade in this combobox and have a second combobox updated to show either employees or contractors that match this trade. There would be a checkbox that indicates whether the second combobox should list employees or if it should list contractors.

I will go ahead with your instructions below for the time being. Are there any other pointers you might be able to give to help me get the above functionality?

Thanks so much, your time is appreciated!

CB55


Hi CB55. Certainly possible to link the Contractors and the Employees to Trades, though not in one table. The relationship between trades and contractors, and trades and employees, is many-to-many. Each contractor can have more than one trade (plumbing, electrical, joinery say), and each trade is a feature of more than one contractor. Many-to-many's are resolved into two one-to-many relationships using an intermediate table - a linking table - which contains the key fields of both joined tables (contractor and trades, or employees and trades). The link table is joined to contractor so that there is a one-to-many between contractor and ContractorTrades, and ContractorTrades is joined to Trades as a many-to-one.

There is a good article about normalisation and table relationships in the forum, at http://www.thescripts.com/forum/thread585228.html

I don't know what the key fields of your tables are, but producing linking tables is quite straightforward. Once done, you need to be able to add the data to them - and for end-users this can be done using a form-subform structure (adapting the contractor main form to include a trades subform, for instance).

-Stewart
Feb 20 '08 #3

jaxjagfan
Expert 100+
P: 254
If you have 2 identical datasets the easiest way to get both into a single list is use a Union query. The datasource for your combo could be something like this:

Expand|Select|Wrap|Line Numbers
  1. Select qryEmployeeTrades.*
  2. Union
  3. Select qryContractorTrades.*
  4.  
Each of the queries could have its own criteria but each must return the same number of columns with the same datatypes.

Hi Stewart,

Thanks for your response. I should probably clarify my goal to make sure that I'm following the right instructions. I have a Tasks table as well as a Tasks form. The Tasks form will be used to add new tasks and indicate the trades required to complete the tasks. I have a TradeID combobox controlled from the Trades table, and I'd like to be able to select a trade in this combobox and have a second combobox updated to show either employees or contractors that match this trade. There would be a checkbox that indicates whether the second combobox should list employees or if it should list contractors.

I will go ahead with your instructions below for the time being. Are there any other pointers you might be able to give to help me get the above functionality?

Thanks so much, your time is appreciated!

CB55
Feb 20 '08 #4

P: 67
Thank you very much! I didn't know it was possible to query from two tables like that. But now is there a way to decide whether to show employees or contractors in this combobox based on the status of a checkbox? I don't imagine I could use a WHERE clause...?

I'm fairly new to this... thanks for your patience! :)

CB55

If you have 2 identical datasets the easiest way to get both into a single list is use a Union query. The datasource for your combo could be something like this:

Expand|Select|Wrap|Line Numbers
  1. Select qryEmployeeTrades.*
  2. Union
  3. Select qryContractorTrades.*
  4.  
Each of the queries could have its own criteria but each must return the same number of columns with the same datatypes.
Feb 20 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.