Passing variable values (complete specifically path of an MDB) inside a SQL query in Excel

va1b4av

New Member
Joined
Jun 1, 2011
Messages
5
Hi Folks,

There's this application we are working on here, written completely in excel and uses Pivot tables. Now, we have a particular pivot table here that gets the data from a SQL query (using Microsoft Query I think).

Here's what I do to get to the query:
Right click on a cell in the Pivot sheet and Go to the Pivit Table Wizard. Subsequently, follow all the steps till I get to the SQL query.

Here's the query I get <table width="550px"></table>
Code:
SELECT `SS Camp 2010`.Country, `SS Camp 2010`.`Product Line Name`, `SS Camp 2010`.`Edition Name`, `SS Camp 2010`.`Promotion Prefix`, `SS Camp 2010`.Info, `SS Camp 2010`.Year, `SS Camp 2010`.Month, `SS Camp 2010`.Week, `SS Camp 2010`.Despatch, `SS Camp 2010`.Intake
FROM `[COLOR=Red][B]G:\topstat\xls-ro\SSCAMP`.`SS Camp 2010` `SS Camp 2010`[/B][/COLOR]
ORDER BY `SS Camp 2010`.Year

Now, the highlighted RED section is a path to an MDB file placed within the same folder. We need to remove all hardcoding references to this path so that in case the entire folder gets moved to some other place (say F:\topstat\xls-ro\....), it does not break.

The MDB file and the Pivot sheet will ALWAYS remain in the same folder structure.

Any help or inputs on this would be appreciated.

Thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Thanks for your reply Sektor..I just tried to use this in the query,

Code:
SELECT `SS Camp 2011`.Country, `SS  Camp 2011`.`Product Line Name`, `SS Camp 2011`.`Edition Name`, `SS Camp  2011`.`Promotion Prefix`, `SS Camp 2011`.Info, `SS Camp 2011`.Year, `SS Camp  2011`.Month, `SS Camp 2011`.Week, `SS Camp 2011`.`Week Number`, `SS Camp  2011`.Despatch, `SS Camp 2011`.Intake
 FROM [B][COLOR=Red]ThisWorkbook.Path.`SS Camp  2011` `SS Camp 2011`[/COLOR][/B]

Fails with the following error:

Could not add the table ' ThisWorkbook.Path.`SS Camp 2011` `SS Camp 2011`'

Is 'ThisWorkBook.Path' not used for VBA code, does it also work for queries?
 
Upvote 0
Rather than:-
Code:
FROM `[COLOR=red][B]G:\topstat\xls-ro[/B][/COLOR]\SSCAMP`.`SS Camp 2010`
try:-
Code:
FROM `[COLOR=red][B].[/B][/COLOR]\SSCAMP`.`SS Camp 2010`
(Not tested here.)
 
Upvote 0
Thanks for your replies guys..I am trying this out on the application..Will post the results here.
thanks again for taking the the time to help
 
Upvote 0
okay guys, I wa able to figure out a solution to this:
Basically if the MDb and the excel reside in the same folder, I can just use the following:

FROM `\SSCAMP`.`SS Camp 2010

However, when the excel and the mdb reside in different locations, this would not work.Any inputs on that would be highly appreciated.
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,152
Members
452,891
Latest member
JUSTOUTOFMYREACH

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