Excel-VBA, MS Access with INNER JOIN

luffy88

New Member
Joined
Feb 13, 2017
Messages
8
Hello,
I have a problem with importing data from ms access to excel with <acronym title="visual basic for applications">VBA</acronym>. I use "ADO Connection" to connect excel with acces.
I have 2 tables in ms access. I want to get the newest comment from table p_comment for products. I tried it with inner join, but i get all comments.
so how can i get only the newest/latest comment for a product?
thank you for your help.

sql= "SELECT p_comment.ID, p_comment.p_id, p_comment.user, p_comment.comment, p_comment.c_date FROM product INNER JOIN p_comment ON product.ID = p_comment.p_id"




p_comment
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]p_id[/TD]
[TD]user[/TD]
[TD]comment[/TD]
[TD]c_date[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]test user[/TD]
[TD]test comment[/TD]
[TD]19.02.2017[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1[/TD]
[TD]test123[/TD]
[TD]comment1[/TD]
[TD]19.02.2017[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]2[/TD]
[TD]test1[/TD]
[TD]comment3[/TD]
[TD]19.02.2017[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]2[/TD]
[TD]test1234[/TD]
[TD]commen4[/TD]
[TD]19.02.2017[/TD]
[/TR]
</tbody>[/TABLE]


product:
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]p_name[/TD]
[TD]p_date[/TD]
[TD]p_desc[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]test[/TD]
[TD]01.02.2017[/TD]
[TD]test[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]hallo[/TD]
[TD]01.02.2017[/TD]
[TD]test[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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