Database query possibilities

percy83

Active Member
Joined
Mar 11, 2009
Messages
278
Dear Excel experts

I’ve got a workbook containing one database query where different projects are listed.
My plan is to also add comments outside the database query range which should be “connected” to that specific project (in this case project number).
Problem is that when the queried file gets bigger and/or smaller (e.i. project added or deleted) these comments dosen’t follow the value they where intended for.



Any suggestions?

Thanks for any help I could get!

Best regards
Per Nilsson
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Welcome, Per.

One approach. Add a new query table to the file pulling the project identifier and comment fields from your current Excel table. Such as "SELECT project_number, comment FROM table".

Now edit your existing query to also pull the comment from this new table. Such as, it now pulls "SELECT * FROM db" and change it to something like
Code:
SELECT db.*, new.comment
FROM db, new_table new
WHERE db.project = new.project

Now always refresh the new comments table query before refreshing the main query.

Regards, Fazza
 
Upvote 0
Is there a way to do this without writing code? I'm not even sure where to enter this code. Thank you!

Welcome, Per.

One approach. Add a new query table to the file pulling the project identifier and comment fields from your current Excel table. Such as "SELECT project_number, comment FROM table".

Now edit your existing query to also pull the comment from this new table. Such as, it now pulls "SELECT * FROM db" and change it to something like
Code:
SELECT db.*, new.comment
FROM db, new_table new
WHERE db.project = new.project

Now always refresh the new comments table query before refreshing the main query.

Regards, Fazza
 
Upvote 0
Welcome, Per.

One approach. Add a new query table to the file pulling the project identifier and comment fields from your current Excel table. Such as "SELECT project_number, comment FROM table".

Now edit your existing query to also pull the comment from this new table. Such as, it now pulls "SELECT * FROM db" and change it to something like
Code:
SELECT db.*, new.comment
FROM db, new_table new
WHERE db.project = new.project

Now always refresh the new comments table query before refreshing the main query.

Regards, Fazza

Hello All,
I have a live data connection feed table in my Excel worksheet and I have created a new table with the key field and extra comments field and it refreshes nicely but I cannot figure out how to incorporate the new query into the existing SQL code for the original live connected table so that they join to re-feed the data back in after refresh. Any ideas?

Thank you,

Lindsay
 
Upvote 0
hi, Lindsay

A live data connection feed table. The specifics of this will impact a solution. A possible slight variation on earlier method is suggested.

That new table with key field and extra comments that refreshes nicely, have it refresh every time a change is made to the comments field that is part of the original live connected table. So that new table is always in synch. Trigger by worksheet change event or whatever works best.

Then upon refresh of the live data connection and you want to get the comments back, if it is not easy to change the table's definition to join in the comments make it a separate update query. So some trigger to do something like "UPDATE main_table M INNER JOIN new_table N ON M.project_number = N.project_number SET M.comment = N.comment". Untested SQL. Trigger could be an on refresh event for live connection or maybe basic worksheet change or whatever works: should be able to work out something without resorting to manual button.

howzat sound?
 
Upvote 0
another thought on this. there is another step needed, I think. before the already suggested UPDATE run this additional one, "UPDATE main_table SET comment = Null"
 
Upvote 0
another thought, UPDATE queries might be a bit slow? consider VBA using worksheet formulas instead to re-populate the comments. regards
 
Upvote 0

Forum statistics

Threads
1,214,661
Messages
6,120,796
Members
448,994
Latest member
rohitsomani

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