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

Compare tables based on Combobox selections

P: 4
Hi,

I have a database to store my analyses (Access 2002, WinXp), the basic structure is:

TABLE 1 = Sample Info
TABLE 2 = Analysis type 1
TABLE 3 = Analysis type 2
TABLE 4 = Analysis type 3

....where each table stores results of a different type of analysis

TABLE 1 contains [SampleID], [SampleName] and other details
TABLE 2, 3 and 4 contain [SampleID], [Chemical], [%] as well as some other fields.

I use the [SampleID] field to link the tables back to TABLE 1, so that when I view the analysis I only see the relevant analyses.

I would like to be able to compare the samples for different types of analysis of the same sample and also be able to compare analyses of different samples.

My idea would be that you have 2 comboboxes for each comparison, e.g.
COMBOBOX 1 = [SampleID] and COMBOBOX 2 = Analysis type
this would let me select the first sample and the type of analysis to compare, then have another 2 comboboxes to set the second sample and analysis type to compare. The results would then appear on a form somehow.

I started by trying to build the table to compare using SQL, I tried using a query with an OUTER JOIN on the various tables, but it only allows me to see chemicals that are in the first table, if any chemicals appear in the second analysis then they are not shown. I'm not sure if this is the right way as I am not sure how to get it to select the types of analysis to compare from the comboboxes - even if I got it to work.

I would like to output something like:

Chemical , Type1 % , Type2 %
Chemical A , 10 , 20
Chemical B , 0 , 30
Chemical C , 50 , 0

I am self-taught in Access and know very little VB (only what I worked out from examples and help files).I am quite happy to muddle around trying to solve this but I think I've exhausted my knowledge. If someone could point me in the right direction I would appreciate it greatly.

Regards

Edd
Feb 9 '07 #1
Share this Question
Share on Google+
5 Replies


nico5038
Expert 2.5K+
P: 3,072
When your [SampleID] is available in all "subtables" (2-3-4), then your outer JOIN should work.
Did you place the Table1 as the "master" for the link and the other 3 as "slaves" ?
(option 2 or 3) arrow lines should point from table1 to the others.

Nic;o)
Feb 10 '07 #2

NeoPa
Expert Mod 15k+
P: 31,494
I'm a little confused by some of what you say. Can you clear up a couple of points for me :
  1. Is there data in the master table (TABLE 1) for every SampleID that exists?
  2. Do you really mean OUTER JOIN?
    An OUTER JOIN in a query is when there is NO link between the tables.
    I suspect, from what you're saying, that you are using a LEFT or RIGHT JOIN.
I would expect that your source should be along the lines of :
Expand|Select|Wrap|Line Numbers
  1. ...
  2. FROM ((([TABLE 1] LEFT JOIN [TABLE 2]
  3.   ON [TABLE 1].SampleID=[TABLE 2].SampleID)
  4.   LEFT JOIN [TABLE 3]
  5.   ON [TABLE 1].SampleID=[TABLE 3].SampleID)
  6.   LEFT JOIN [TABLE 4]
  7.   ON [TABLE 1].SampleID=[TABLE 4].SampleID)
  8. ...
Feb 11 '07 #3

P: 4
I'm a little confused by some of what you say. Can you clear up a couple of points for me :
  1. Is there data in the master table (TABLE 1) for every SampleID that exists?
  2. Do you really mean OUTER JOIN?
    An OUTER JOIN in a query is when there is NO link between the tables.
    I suspect, from what you're saying, that you are using a LEFT or RIGHT JOIN.
I would expect that your source should be along the lines of :
Expand|Select|Wrap|Line Numbers
  1. ...
  2. FROM ((([TABLE 1] LEFT JOIN [TABLE 2]
  3.   ON [TABLE 1].SampleID=[TABLE 2].SampleID)
  4.   LEFT JOIN [TABLE 3]
  5.   ON [TABLE 1].SampleID=[TABLE 3].SampleID)
  6.   LEFT JOIN [TABLE 4]
  7.   ON [TABLE 1].SampleID=[TABLE 4].SampleID)
  8. ...
Hi,

Firstly thank you both for your help.

I have set up a query as Nico suggested with the arrows going the correct way (my initial attempt had them the right way as well). This gives me the same FROM statement as NeoPa has listed.

I'm now trying to work out which fields I should be including in the SELECT part, each table (TABLE 2, 3 and 4) has a [Chemical] and [%] field. If I select both these from each table then I get a table with multiple chemical and % columns, SELECT statement is:
Expand|Select|Wrap|Line Numbers
  1. ...
  2. SELECT [TABLE1].[SampleID], 
  3. [TABLE 2].Chemical, [TABLE 2].[%], 
  4. [TABLE 3].Chemical, [TABLE 3].[%], 
  5. [TABLE 4].Chemical, [TABLE 4].[%]
  6.  
Feb 13 '07 #4

P: 4
oops...hit submit by accident and timed out editing post....

I am assuming I need this layout to enable the comparison between samples? Looking at the worksheet it appears to be comparing analyses for the same sample (although with multiple repeated lines of same chemical) i.e it appears to take Chemical A in TABLE 2 and list it against each chemical in TABLE 3, then take Chemical B and list against every chemical in TABLE 3 etc.

If so how would I go about getting to select which sample/analysis to compare? I will have a try but I'm not sure what commands I would need to use, would it be a simple LIKE function as I have been using for searches? but adjusted to suit multiple inputs?
Expand|Select|Wrap|Line Numbers
  1. Me.Filter = "[Chemical] LIKE '*" & TXTSEARCH.Value & "*' OR [Synonyms] LIKE '*" & TXTSEARCH.Value & "*'"
  2.  
Once again thank you for your help and patience! I shall try sorting out a form to enable me to select which analyses to compare.

Regards

Edd
Feb 13 '07 #5

NeoPa
Expert Mod 15k+
P: 31,494
First, use the AS keyword in your query to rename the returned fields :
Expand|Select|Wrap|Line Numbers
  1. SELECT [TABLE1].[SampleID], 
  2.        [TABLE 2].Chemical AS Chem2, [TABLE 2].[%] AS PC2, 
  3.        [TABLE 3].Chemical AS Chem3, [TABLE 3].[%] AS PC3, 
  4.        [TABLE 4].Chemical AS Chem4, [TABLE 4].[%] AS PC4
  5. ...
Feb 13 '07 #6

Post your reply

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