Create Query Linking Two Tables Together

Sypher7

New Member
Joined
Oct 30, 2013
Messages
18
Hello,

I have two tables. One labelled "Records" and one labelled "Comments".

I both tables I have an "Account Number"

However in the records table, there will only ever be one record for each account. In the comments table there can be any number of records for that account.

The idea behind this is that everytime a new action is taken on an account a new comment is logged, using a continuous subform i have it showing a comment history.

I need to create query which brings back certain fields from the records table but also the comment from the comments table.

So far I have got it to work with the exception that each comment shows as a new record in my finished report.

I am after a way of combining all of the comments into one field and then pulling it through so that each account will only show up one in my finished report.

Can anyone suggest a way of doing it please as I am a bit stumped.

Thanks
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
if you want ALL Accts to show ,even if they do not have a comment,
then you must create an OUTER join.
in the query, join the 2 tables, then dbl-click the join line connecting them,
set the join type to all records in tAccts, Some in tComments.
bring down the fields you need,
save, run.
 
Upvote 0
This has been viewed a few times with no comments yet so just to give some more info around what i need:

These are my (example) tables:

Table 1
Account-NumberAccount-NameIn-Query
AC001Account 1Yes
AC002Account 2No
AC003Account 3Yes

<tbody>
</tbody>


Table 2
Account-NumberComment
AC001Received-Documents
AC001Documents-Incorrect
AC001Account-Placed-in-Query
AC002Received-Documents
AC002Documents-Correct
AC003Received-Documents
AC003Documents-Incorrect
AC003New-Documents-Still-Incorrect
AC003Account-Placed-in-Query

<tbody>
</tbody>


This is what I want the report to look like:

Account NumberAccount NameIn QueryComment
AC001Account 1YesReceived-Documents
Documents-Incorrect
Account-Placed-in-Query
AC003Account 3YesReceived-Documents
Documents-Incorrect
New-Documents-Still-Incorrect
Account-Placed-in-Query

<tbody>
</tbody>


<colgroup><col><col><col><col></colgroup><tbody>
</tbody>


This is what it actually looks like

Account NumberAccount NameIn QueryComment
AC001Account 1YesReceived-Documents
AC001Account 1YesDocuments-Incorrect
AC001Account 1YesAccount-Placed-in-Query
AC003Account 3YesReceived-Documents
AC003Account 3YesDocuments-Incorrect
AC003Account 3YesNew-Documents-Still-Incorrect
AC003Account 3YesAccount-Placed-in-Query

<tbody>
</tbody>













Thanks
 
Upvote 0
if you want ALL Accts to show ,even if they do not have a comment,
then you must create an OUTER join.
in the query, join the 2 tables, then dbl-click the join line connecting them,
set the join type to all records in tAccts, Some in tComments.
bring down the fields you need,
save, run.

Hi Ranman, you must have been typing at the same time as me,

Not quite what i was after, apologies i forgot to say i only wanted the records from the first table if they are flagged as a query.

Please see my example i just posted.

thanks for you help.
 
Upvote 0
the results you typed look lik a pivot table

I've never made a pivot table in access
I've only used Excel for that

but I'm sure you can do it in acccess somehow
 
Upvote 0
You should do your query as
Code:
SELECT Table1.AccountNbr, Table1.AccountName, Table1.InQry, Table2.Comments
FROM Table1 LEFT JOIN Table2 ON Table1.AccountNbr = Table2.AccountNbr
WHERE Table1.InQry=True;
As for the report, all you have to do is base it on the query and group it on the accountnbr.
 
Upvote 0
So basically what i found out is that yes i am after a pivot table and in Access 2010 you could do it but they removed the feature.

I have set up an excel pivot table that has a connection to the access table, i run my query to create the table then open the excel file which automatically updates on open.

Its a shame as i intended for anyone to just be able to open it and run the query but at least this is a workaround.

Didn't seem like it could be possible in access.

Baderms thanks for your suggestion i will keep looking into that.
 
Upvote 0
A pivot table maybe, but I've never used them in Access either. Maybe this calls for the power of a report? In a report, you can group by Account number (this grouping level can include the account name and any other account related data) and each comment would be a record under the related account. The output would look like what you've displayed as a desired result. A query cannot display as you've posted because it can't leave holes where you have no data in your example.

I see that post #6 says "as for the report" but I can't find any prior mention of a report so I missed that.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top